@@ -1036,7 +1036,7 @@ Its main purpose is to provide a space for resource control that affects all cor
10361036Resource control at the top level is a useful tool for organizing applications, frameworks, and libraries.
10371037
10381038> Thus, the desire to abandon colored functions is the main motivation for implementing `Scope`.
1039- > **Colored functions** allow Scope to be avoided altogether , as each coroutine would act as a `Scope` for its children.
1039+ > **Colored functions** allow ` Scope` to be avoided, as each coroutine would act as a `Scope` for its children.
10401040
10411041#### Point of Responsibility
10421042
@@ -1047,10 +1047,7 @@ This can become a source of errors, as resources are allocated without explicit
10471047Scope helps solve this problem by implementing responsibility for coroutine ownership.
10481048
10491049```php
1050-
1051- function subtask() {
1052-
1053- }
1050+ function subtask(): void {}
10541051
10551052function task(): void
10561053{
@@ -1183,8 +1180,6 @@ When the `await $scope->directTasks()` has completed,
11831180the coroutine created by ` processUser ` will not stop its execution.
11841181
11851182The ` finally ` block calls ` $scope->dispose() ` , which cancels all coroutines that were created within the ` Scope ` .
1186- Calling ` dispose() ` explicitly cancels all zombie coroutines with a warning message.
1187-
11881183You can also use the ` disposeAfterTimeout ` and ` disposeSafely ` methods
11891184as alternative scenarios for cleaning up a ` Scope ` , see [ Scope disposal] ( #scope-disposal ) .
11901185
@@ -1358,7 +1353,7 @@ function connectionChecker($socket, callable $cancelToken): void
13581353 return;
13591354 }
13601355
1361- Async\delay(1000);
1356+ Async\delay(1000); // throw CancellationException if canceled
13621357 }
13631358}
13641359
@@ -1374,7 +1369,7 @@ function connectionHandler($socket): void
13741369
13751370 spawn with $scope use($socket, $scope) {
13761371
1377- $limiterScope = Scope::inherit();
1372+ $limiterScope = Scope::inherit(); // child scope for connectionLimiter and connectionChecker
13781373
13791374 $cancelToken = fn(string $message) => $scope->cancel(new CancellationException($message));
13801375
@@ -1729,6 +1724,10 @@ The `async` block does the following:
17291724The ` async ` block allows for describing groups of coroutines in a clearer
17301725and safer way than manually using ` Async\Scope ` .
17311726
1727+ > The ` async ` block is similar to the ` async ` function in ** JavaScript** , ` suspended ` in ** Kotlin** , and ** Python** .
1728+ > You can think of an ` async ` block as a direct analog of ** colored functions** .
1729+ > This also means that if an RFC introducing colored functions is created, async blocks will no longer be needed.
1730+
17321731* ** Advantages** : Using ` async ` blocks improves code readability and makes it easier to analyze with static analyzers.
17331732* ** Drawback** : an ` async ` block is useless if ` Scope ` is used as an object property.
17341733
0 commit comments