Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Add fromThrowable support for fns returning Promise #9

Closed
peterboyer opened this issue Dec 6, 2021 · 1 comment
Closed

Add fromThrowable support for fns returning Promise #9

peterboyer opened this issue Dec 6, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@peterboyer
Copy link
Owner

peterboyer commented Dec 6, 2021

Currently fromThrowable doesn't play well with functons that return a Promise:

fromThrowable(fnReturnPromise) => Result<Promise<Value>, Error> where we actually want Promise<Result<Value, Error>>

This could be solved as a seperate method, like fromThrowableAsync which accepts only Promise<T> returning functions, or maybe I can infer the return type statically, and then also correctly wrap the given fn to inspect it's return value and wrap if it's a promise accordingly (which would keep the library's API terse and simple).

@peterboyer peterboyer added the bug Something isn't working label Dec 6, 2021
@peterboyer
Copy link
Owner Author

Solved by extending fromThrowable to support Promises, both with TypeScript type inferrence AND checking return type of wrapped function for potential Promise and then wrapping with ok and err respectively.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant