4 karma · joined Jul 15, 2014 (12y ago) · 10 submissions
comment 7mo ago · link · parent
comment 7mo ago · link · parent
To me that sounds like dropping the task on the floor. Specifically, this will not invoke any finally {} blocks:
More correctly, you should invoke `return()` on the generator. Otherwise, you won't provide execution guarantees. This is how Effection does it. There is no equivalent in async functions, so it sounds like the same problem would apply to the GC technique.
comment 2y ago · link · parent
Built on those delimited continuations is structured concurrency for JavaScript (https://frontside.com/effection)
comment 2y ago · link · parent
Just tell them that they already know them.
`yield*` is
- a superset of `await` so if you understand `await`, you understand `yield*`
- infinitely more powerful because it can handle any effect, not just Promise resolution.
- It's just javascript syntax that predates `await`
5.
Effection 3.0 – Structured Concurrency and Effects for JavaScript(frontside.com ↗)
6 points · by cowboyd · 2y ago · 2 comments
7.
The Await Event Horizon in JavaScript(frontside.com ↗)
6 points · by cowboyd · 2y ago · 2 comments
comment 4y ago · link · parent
comment 4y ago · link · parent
Let's say, for example that I call `doTasks()` with 10 separate tasks. Before any of them can complete, one of them fails. What happens to the other 9? In your example, they are "leaked" because they will continue running, even though the scope that was awaiting their results in gone. Using a "worker pool" as in the example, it might go something like this:
async function doTasks(tasks = []) {
let workerpool = new WorkerPool();
try {
for (let task of tasks) {
workerpool.exec("my task", task);
}
let results = await workerpool.all();
// do stuff with results
} finally {
// no matter the outcome, nothing outlives this scope.
await workerpool.destroy();
}
}
It should be noted that cancellation, i.e. the ability to "destroy" a concurrent task is a necessary primitive for structured concurrency. You can think of it as the equivalent of automatically releasing memory at the end of a lexical scope.There is already an implementation of Structured Concurrency for JavasScript here https://frontside.com/effection
comment 5y ago · link · parent
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...