4 ms·
For coroutines look at structured concurrency https://openjdk.org/jeps/437 https://openjdk.org/jeps/437
by okeuro49 3y ago
For coroutines look at structured concurrency https://openjdk.org/jeps/437 https://openjdk.org/jeps/437
- revskill 3y agoWhat does structure concurrency mean ? What are other kinds of concurrency ?
- ohgodplsno 3y agoThis is good reading on the subject: https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ https://vorpus.org/blog/notes-on-structured-concurrency-or-g... There's a single other kind of concurrency: unstructured concurrency. Which is where you just start threads/goroutines/coroutines/etc and they just... all do their own little thing ? They can return at any time, have no parents, etc. Structured concurrency is about making a tree of concurrent processes. You may have a parent job, that has children. Cancelling this job will cancel all its children. For example, you may have a job that's linked to an UI (so it needs to stop the moment that UI is gone), to a socket (so it needs to stop the moment the socket closes), or to nothing and is a global scope (that will keep running as long as your OS doesn't exit the process). These scopes can in turn have their own children and their own scopes. And maybe you have a task way, way down in your tree that spawns two tasks: one is a long running task that must exit the moment its parent stops ("the user clicked on cancel"), one is a long running task that must stay alive as long as necessary ("the user's data is being uploaded to a server in the background"). With unstructured concurrency, you can't really express that. With structured concurrency, just pass the appropriate scope down.