4 ms·
The advantage is that it provides guarantees, that wouldn't be there otherwise. Let's for example say one of those 4 tasks would write to a file. With structur
by Matthias247 4y ago
The advantage is that it provides guarantees, that wouldn't be there otherwise.
Let's for example say one of those 4 tasks would write to a file. With structured concurrency you have a guarantee that once the supertask finishes, the file is no longer in use. Without structured concurrency you won't have that, and a subtask might error on trying to use the file or find garbage data in it. Running the supertask in a loop with structured concurrency would have no risk of running into resource contention, while without it there is that risk.
Plus structured concurrency also helps adding a deterministic bound on the amount of concurrency in the system, while just spawning more background tasks can lead to concurrency grow in an unbounded fashion.
> In Go for example, I don't remember having to clean up fibers manually.
The equivalent in Go would be to wait for subtasks to complete, using the WaitGroup pattern. And to notify the subtasks that they should complete using "Context".
- didibus 4y agoMy code waits for all futures to complete, that's what: (run! deref [f1 f2 f3 f4]) does.