You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: basic.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2896,6 +2896,24 @@ The `Async\getCoroutines()` method returns an array of all coroutines in the app
2896
2896
|**Java (Loom)**| Virtual threads (experimental), classic `Thread`/`Future`|**Under development** (drafting `StructuredTaskScope`) |**No** (virtual threads are “just calls”) |`Thread.interrupt()` or `Future.cancel()`, details evolving | Standard try/catch + Executor; Loom may introduce structured concurrency, still experimental |**Medium** (familiar threads, but Loom is new/experimental) | Could greatly simplify concurrency while remaining compatible with existing Java code |
2897
2897
|**Erlang/Elixir**| Actor model (lightweight processes) + message passing, “let it crash” |**Yes.** Supervisor trees |**No**| Kill the process from outside, or it crashes & restarts | Powerful supervision system: if a process crashes, the supervisor restarts it. Very fault-tolerant. |**Medium** (actor model is straightforward but requires a shift) | Renowned for high fault tolerance. “Supervisor trees” provide robust structured concurrency and auto-restart. Different paradigm from `await`/tasks — message-based and “let it crash” philosophy. |
2898
2898
2899
+
#### Parallels with Java Loom
2900
+
2901
+
This **RFC** unintentionally contains many parallels with the Java Loom StructuredTaskScope API,
|**Creation**|`new Scope()` or `Scope::inherit()` to group coroutines. |`new StructuredTaskScope<>()` or specialized subtypes to manage forked threads. |
2907
+
|**Task Launch**|`spawn with $scope someTask()` or `async $scope { … }`. |`scope.fork(() -> someTask())` inside the StructuredTaskScope block. |
2908
+
|**Hierarchy**| Scopes can form a tree (child scopes). Canceling a parent scope cancels its children. |`StructuredTaskScope` can nest calls (`fork()` in sub-scopes). Canceling/closing can stop child tasks. |
2909
+
|**Awaiting**|`await $scope->directTasks()` or `await $scope->allTasks()`. |`scope.join()` to wait for all forked tasks. |
2910
+
|**Bounded Execution**|`async bounded $scope { ... }` forcibly cancels child tasks when the main block finishes. | The structured concurrency block ends when the main thread completes; sub-tasks are then joined or canceled. |
2911
+
|**Cancellation**|`scope->cancel()` raises `CancellationException` in all subtasks. |`scope.shutdown()` or `scope.close()` (interrupt the tasks). |
2912
+
|**Exception Handling**| Exceptions bubble up. You can use `Scope::setExceptionHandler()` or `try/catch` around `await`. | Exceptions in subtasks can be aggregated. `scope.join()` may throw or you can call `scope.throwIfFailed()`. |
2913
+
|**Automatic Cleanup**|`dispose()`, `disposeSafely()`, or `disposeAfterTimeout()` forcibly or safely clean up children. |`try (var scope = new StructuredTaskScope<>()) { ... }` auto-closes tasks on exiting the try-with-resources. |
2914
+
|**Context Inheritance**| Each `Scope` has a `Context`. Child scopes inherit from the parent. | Typically uses `ScopedValues` or thread-locals. There’s no official “Context” object with inheritance built-in. |
2915
+
|**Goals**| Transparent coroutines, grouped for structured concurrency, safe cancellation, no function color. | Virtual threads for structured concurrency and easy parallelism, building on Java’s thread model. |
0 commit comments