Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 8af69b4

Browse files
committed
Update basic.md: add parallels between PHP True Async and Java Loom StructuredTaskScope
1 parent 09a2b28 commit 8af69b4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

basic.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,24 @@ The `Async\getCoroutines()` method returns an array of all coroutines in the app
28962896
| **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 |
28972897
| **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. |
28982898

2899+
#### Parallels with Java Loom
2900+
2901+
This **RFC** unintentionally contains many parallels with the Java Loom StructuredTaskScope API,
2902+
which is very similar to this **RFC**.
2903+
2904+
| **Feature** | **PHP True Async (Scope)** | **Java Loom (StructuredTaskScope)** |
2905+
|-------------------------|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
2906+
| **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. |
2916+
28992917

29002918
## Backward Incompatible Changes
29012919

0 commit comments

Comments
 (0)