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
When there are some exceptions thrown in chain, it will not reject or resolve, it just hang without any helpful information.
Steps to reproduce
Given the following example, it didn't resolve or reject till timeout.
import{task,of}from'folktale/concurrency/task'test.only('exception',async()=>{awaittask(({resolve, reject})=>setTimeout(()=>resolve(1),10)).chain(x=>{throw'error'// emulate some errorsreturnof(2)}).run().promise()})// Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Expected behaviour
I hope when exception thrown, it shall reject automatically.
Environment
OS: macOS 10.12.6
JavaScript VM: 8
Folktale version: 2
Additional information
The following test will be rejected straight away
import{task,of}from'folktale/concurrency/task'test.only('exception',async()=>{awaitof(1).chain(x=>{throw'error'// emulate some errors by typo or somethingreturnof(2)}).run().promise()})
The text was updated successfully, but these errors were encountered:
Ah, yes, unlike Promises, Task won't catch errors for you automatically. You need to wrap those parts in a try/catch and handle them accordingly. I just realised this isn't documented, but it's a deliberate design decision.
In general, I believe that if some exceptional condition that you weren't expecting happens at runtime, your program should crash, then restart in a clean, well-known state. If your program continues to run, you don't know in which state you are anymore, or even if that's a valid state in your program. That's extremely dangerous since you can't predict your program's behaviour. The node documentation does a good job at explaining the dangers of catch-and-continue that Promises use.
Catching errors automatically has some other issues in that errors thrown asynchronously can't be caught (the stack frames when the error is thrown is not under the function that started the process anymore).
While the example you posted should crash the process, from what I understood it's not doing that, and instead it's just not completing the test case instead. That may be your test runner handling these errors for you (e.g.: with process.on('uncaughtException')). If you run it directly it crashes the process, as expected:
When there are some exceptions thrown in
chain
, it will not reject or resolve, it just hang without any helpful information.Steps to reproduce
Given the following example, it didn't resolve or reject till timeout.
Expected behaviour
I hope when exception thrown, it shall reject automatically.
Environment
Additional information
The following test will be rejected straight away
The text was updated successfully, but these errors were encountered: