Skip to content

Commit

Permalink
Merge pull request #68 from swan-io/allow-typing-from-promise
Browse files Browse the repository at this point in the history
Allow typing fromPromise
  • Loading branch information
bloodyowl authored Mar 11, 2024
2 parents 5ed4bff + d3afa85 commit 2aaa761
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Future.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export class Future<A> {
/**
* Converts a Promise to a Future\<Result\<Value, unknown>>
*/
static fromPromise<A>(promise: Promise<A>): Future<Result<A, unknown>> {
static fromPromise<A, E = unknown>(
promise: Promise<A>,
): Future<Result<A, E>> {
return Future.make((resolve) => {
promise.then(
(ok) => resolve(Result.Ok(ok)),
(reason) => resolve(Result.Error(reason)),
(error: E) => resolve(Result.Error(error)),
);
});
}
Expand Down

0 comments on commit 2aaa761

Please sign in to comment.