Skip to content

Commit

Permalink
Allow typing fromPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Mar 5, 2024
1 parent 5ed4bff commit d3afa85
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 d3afa85

Please sign in to comment.