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

Commit aa17898

Browse files
committed
+ base.rfc
1 parent be45b80 commit aa17898

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

base.rfc

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Please use the diagrams from the table to simplify understanding.
5454

5555
This **RFC** describes the **API** and **new syntax** for writing concurrent code in PHP, which includes:
5656

57-
=== **Coroutine** ===
57+
=== Coroutine ===
5858
A lightweight execution thread that can be suspended (`suspend`) and resumed.
5959
Example:
6060
<code php>
@@ -143,7 +143,7 @@ echo "Next line\n";
143143

144144
Output:
145145

146-
</code>
146+
<code>
147147
Next line
148148
File content: ...
149149
</code>
@@ -188,7 +188,7 @@ echo "Next line\n";
188188

189189
Output:
190190

191-
</code>
191+
<code>
192192
Hello, World
193193
Next line
194194
Goodbye, World
@@ -450,7 +450,7 @@ will be thrown from the suspension point.
450450

451451
=== Coroutine Lifecycle ===
452452

453-
</code>plantuml
453+
<code>plantuml
454454
@startuml
455455
state "Created" as Created
456456
state "Queued" as Queued
@@ -919,7 +919,7 @@ spawn with hiPriority() {
919919

920920
**Expected output:**
921921

922-
</code>
922+
<code>
923923
high priority
924924
normal priority
925925
</code>
@@ -952,7 +952,7 @@ spawn example('Universe');
952952

953953
Expected output:
954954

955-
</code>
955+
<code>
956956
Hello, World!
957957
Hello, Universe!
958958
Goodbye, World!
@@ -1020,7 +1020,7 @@ echo "Back to the main flow";
10201020

10211021
Expected output:
10221022

1023-
</code>
1023+
<code>
10241024
Hello, World!
10251025
Back to the main flow
10261026
Goodbye, World!
@@ -1051,7 +1051,7 @@ $couroutine->cancel();
10511051

10521052
**Expected output:**
10531053

1054-
</code>
1054+
<code>
10551055
Hello, World!
10561056
Caught exception: cancelled at ...
10571057
Goodbye, World!
@@ -1078,7 +1078,7 @@ echo "Main flow";
10781078

10791079
**Expected output:**
10801080

1081-
</code>
1081+
<code>
10821082
Start reading file1.txt
10831083
Start reading file2.txt
10841084
Main flow
@@ -1356,7 +1356,7 @@ try {
13561356

13571357
**Expected output:**
13581358

1359-
</code>
1359+
<code>
13601360
Caught exception: Error
13611361
</code>
13621362

@@ -1461,15 +1461,15 @@ $scope->awaitCompletion(Async\signal(SIGTERM));
14611461

14621462
**Expected output:**
14631463

1464-
</code>
1464+
<code>
14651465
Sibling task 1
14661466
Sibling task 2
14671467
Sibling task 3
14681468
</code>
14691469

14701470
**Structure:**
14711471

1472-
</code>
1472+
<code>
14731473
main() ← defines a $scope
14741474
└── $scope = new Scope()
14751475
├── task1() ← runs in the $scope
@@ -1536,7 +1536,7 @@ $scope->awaitCompletion(Async\signal(SIGTERM));
15361536

15371537
**Expected output:**
15381538

1539-
</code>
1539+
<code>
15401540
Sibling task 1
15411541
Sibling task 2
15421542
Sibling task 3
@@ -1574,7 +1574,7 @@ try {
15741574

15751575
**Expected output:**
15761576

1577-
</code>
1577+
<code>
15781578
Error occurred
15791579
</code>
15801580

@@ -1597,7 +1597,7 @@ try {
15971597

15981598
**Expected output:**
15991599

1600-
</code>
1600+
<code>
16011601
Caught exception: cancelled at ...
16021602
</code>
16031603

@@ -1632,7 +1632,7 @@ spawn with $scope use($scope) {
16321632

16331633
**Expected output:**
16341634

1635-
</code>
1635+
<code>
16361636
Finally
16371637
Caught exception: cancelled at ...
16381638
</code>
@@ -1655,7 +1655,7 @@ A hierarchy can be a convenient way to describe an application as a set of depen
16551655
* Child tasks MUST NOT control or wait for their parent tasks.
16561656
* It is correct if tasks at the same hierarchy level are only connected to tasks of the immediate child level.
16571657

1658-
</code>
1658+
<code>
16591659
WebServer
16601660
├── Request Worker
16611661
│ ├── request1 task
@@ -1672,7 +1672,7 @@ Each request may spawn subtasks. On the same level, all requests form a group of
16721672

16731673
`Scope` is fit for implementing this concept:
16741674

1675-
</code>
1675+
<code>
16761676
WebServer
16771677
├── Request Worker
16781678
│ ├── request1 Scope
@@ -1815,7 +1815,7 @@ Let's examine how this example works.
18151815
As soon as the client disconnects, `connectionChecker` will cancel all coroutines related to the request.
18161816
6. If the main `Scope` is closed, all coroutines handling requests will also be canceled.
18171817

1818-
</code>
1818+
<code>
18191819
GLOBAL <- globalScope
18201820
18211821
├── socketListen (Scope) <- rootScope
@@ -1869,7 +1869,7 @@ $scope->cancel();
18691869

18701870
**Expected output:**
18711871

1872-
</code>
1872+
<code>
18731873
</code>
18741874

18751875
=== Scope disposal ===
@@ -1920,7 +1920,7 @@ $scope->disposeSafely();
19201920

19211921
**Expected output:**
19221922

1923-
</code>
1923+
<code>
19241924
Root task
19251925
Warning: Coroutine is zombie at ... in Scope disposed at ...
19261926
Warning: Coroutine is zombie at ... in Scope disposed at ...
@@ -1965,7 +1965,7 @@ $scope->dispose();
19651965

19661966
**Expected output:**
19671967

1968-
</code>
1968+
<code>
19691969
Warning: Coroutine is zombie at ... in Scope disposed at ...
19701970
Warning: Coroutine is zombie at ... in Scope disposed at ...
19711971
Warning: Coroutine is zombie at ... in Scope disposed at ...
@@ -2013,7 +2013,7 @@ unset($service);
20132013

20142014
**Expected output:**
20152015

2016-
</code>
2016+
<code>
20172017
Task 1
20182018
Warning: Coroutine is zombie at ... in Scope disposed at ...
20192019
Task 2
@@ -2322,7 +2322,7 @@ $scope->awaitCompletion(Async\signal(SIGTERM));
23222322

23232323
**Structure:**
23242324

2325-
</code>
2325+
<code>
23262326
main() ← defines a $scope
23272327
└── $scope = new Scope()
23282328
├── task1() ← runs in the $scope
@@ -2467,7 +2467,7 @@ $scope->dispose();
24672467

24682468
**Expected output:**
24692469

2470-
</code>
2470+
<code>
24712471
</code>
24722472

24732473
There are no warnings about **zombie coroutines** in the output
@@ -2547,7 +2547,7 @@ await $taskGroupParent;
25472547

25482548
**Structure:**
25492549

2550-
</code>
2550+
<code>
25512551
main()
25522552
└── $taskGroupParent = new TaskGroup() <- parent task group scope
25532553
├── $taskGroupChild = new TaskGroup(Scope::inherit()) <- child task group scope
@@ -2584,7 +2584,7 @@ $taskGroup->cancel(new \Async\CancellationException('Custom cancellation message
25842584

25852585
**Expected output:**
25862586

2587-
</code>
2587+
<code>
25882588
Task was cancelled: Custom cancellation message
25892589
</code>
25902590

@@ -2675,7 +2675,7 @@ try {
26752675

26762676
**Expected output:**
26772677

2678-
</code>
2678+
<code>
26792679
Caught exception: TaskGroup was cancelled at ...
26802680
</code>
26812681

@@ -3108,7 +3108,7 @@ print_r($results);
31083108

31093109
Expected output:
31103110

3111-
</code>text
3111+
<code>text
31123112
Array
31133113
(
31143114
[0] => ... // result of fetchUserData()
@@ -3344,7 +3344,7 @@ An uncaught exception in a coroutine follows this flow:
33443344
7. If there is no parent scope, the exception falls into `globalScope`,
33453345
where the same rules apply as for a regular scope.
33463346

3347-
</code>
3347+
<code>
33483348
puml
33493349
@startuml
33503350
start
@@ -3509,7 +3509,7 @@ If an exception occurs in a coroutine created within a **child Scope**,
35093509
it will be passed to the `setChildScopeExceptionHandler` handler and will not affect
35103510
the operation of the service as a whole.
35113511

3512-
</code>
3512+
<code>
35133513
puml
35143514
@startuml
35153515
actor Client
@@ -3703,7 +3703,7 @@ try {
37033703

37043704
Expected output:
37053705

3706-
</code>
3706+
<code>
37073707
The end
37083708
</code>
37093709

@@ -3732,7 +3732,7 @@ try {
37323732

37333733
Expected output:
37343734

3735-
</code>
3735+
<code>
37363736
Caught CancellationException
37373737
The end
37383738
</code>

0 commit comments

Comments
 (0)