You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeChainPFn<A,B>=(a: A)=>Promise<B>;constchainP=<A,B,E=UnknownError>(fn: ChainPFn<A,B>,handler?: (err: unknown)=>E)=>chain(// TODO: need to wrap fn inside a try catch(a: A)=>Task.fromPromise(fn(a)).catch(err=>{if(handler){returnTask.reject(handler(err));}else{returnTask.reject(newUnknownError(err)asanyasE);}}));
This can allow something like
asyncfunctionfoo(n: number){if(n===1){throw'Buu';}returnn;}// If the function fails then the error is wrapped in UnknownErrorTask.resolve(1).pipe(chainP(val=>foo(val)));// Task<number, UnknownError>// If you provide a handler you can control the type of errorTask.resolve(1).pipe(chainP(val=>foo(val),err=>errasstring));// Task<number, UnknownError | string>
The text was updated successfully, but these errors were encountered:
Probably something in these lines:
This can allow something like
The text was updated successfully, but these errors were encountered: