Effection: For When Async/Await Is Not Enough
frontside.com
frontside.com
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.
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-g...
- https://elizarov.medium.com/structured-concurrency-722d765aa...