4 ms·
Effection: For When Async/Await Is Not Enough
- nathanaldensr 5y agoI'm not sure I buy the premise for the library's existence, at least with how the author describes it. The setTimeout code in particular feels very contrived. If you don't want to spawn fire-and-forget functions then just don't spawn them. Like an equivalent in C#: async Task DoSomethingAsync() { // Oh no! This task is fire-and-forget! Whatever shall I do?!? Task.Run(async () => await DoSomethingElseAsync()); ... } Just... don't write code like that. The natural function of Promises when awaited is to wait for the Promise to become fulfilled. The "timed Promise" concept is interesting. In C#, we use CancellationToken for that along with some kind of timer that requests cancellation of the token after an interval. I think adding something like cancellation tokens to JavaScript might be a better course of action.
- cowboyd 5y ago> I'm not sure I buy the premise for the library's existence, at least with how the author describes it. Just do a google search for "structured concurrency". These ideas did not come out of a vacuum, but instead from years of research in language communities ranging from C/C++ to Java, Swift, and Python. Effection is just these same ideas projected into the world of JavaScript. You may find the following resources are helpful - https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ https://vorpus.org/blog/notes-on-structured-concurrency-or-g... - https://elizarov.medium.com/structured-concurrency-722d765aa952 https://elizarov.medium.com/structured-concurrency-722d765aa... - https://openjdk.java.net/jeps/8277129 https://openjdk.java.net/jeps/8277129 - https://www.wwdcnotes.com/notes/wwdc21/10134/ https://www.wwdcnotes.com/notes/wwdc21/10134/