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: base.rfc
+20-99Lines changed: 20 additions & 99 deletions
Original file line number
Diff line number
Diff line change
@@ -450,46 +450,23 @@ will be thrown from the suspension point.
450
450
451
451
=== Coroutine Lifecycle ===
452
452
453
-
<code>plantuml
454
-
@startuml
455
-
state "Created" as Created
456
-
state "Queued" as Queued
457
-
state "Running" as Running
458
-
state "Suspended" as Suspended
459
-
state "Completed" as Completed
460
-
state "Pending Cancellation" as Pending
461
-
462
-
[*] --> Created
463
-
Created --> Queued : spawn
464
-
Queued --> Running : enqueue
465
-
Running --> Suspended : suspend
466
-
Suspended --> Queued : resume
467
-
Running --> Completed : return/exit/throw
468
-
469
-
Pending --> Completed : cleanup finished
470
-
Suspended --> Pending : cancel() requested
471
-
Queued -> Pending : cancel() requested
472
-
473
-
Completed --> [*] : onFinally()
474
-
475
-
@enduml
476
-
</code>
453
+
{{ :rfc:true_async:coroutine-lifecycle.svg |}}
477
454
478
455
This state diagram illustrates the lifecycle of a coroutine, showing how it transitions through various states during its execution:
479
456
480
457
**States:**
481
-
- **Created** – The coroutine has been defined but not yet started.
482
-
- **Queued** – The coroutine is queued
483
-
- **Running** – The coroutine is actively executing.
484
-
- **Suspended** – Execution is paused, usually waiting for a result or I/O.
485
-
- **Completed** – The coroutine has finished successfully (via `return` or `exit`).
486
-
- **Pending Cancellation** – A cancellation was requested; the coroutine is cleaning up.
458
+
- **Created** – The coroutine has been defined but not yet started.
459
+
- **Queued** – The coroutine is queued
460
+
- **Running** – The coroutine is actively executing.
461
+
- **Suspended** – Execution is paused, usually waiting for a result or I/O.
462
+
- **Completed** – The coroutine has finished successfully (via `return`).
463
+
- **Pending Cancellation** – A cancellation was requested; the coroutine is cleaning up.
487
464
488
465
**Key Transitions:**
489
-
- `spawn` moves a coroutine from **Created** to **Running**.
490
-
- `suspend` and `resume` move it between **Running** and **Suspended**.
491
-
- `return/exit` ends it in **Completed**.
492
-
- `cancel()` initiates cancellation from **Running** or **Suspended**, leading to **Pending Cancellation**, and finally **Cancelled**.
466
+
- `spawn` moves a coroutine from **Created** to **Running**.
467
+
- `suspend` and `resume` move it between **Running** and **Suspended**.
468
+
- `return/exit` ends it in **Completed**.
469
+
- `cancel()` initiates cancellation from **Running** or **Suspended**, leading to **Pending Cancellation**, and finally **Cancelled**.
493
470
494
471
=== `Coroutine` state check methods ===
495
472
@@ -3344,37 +3321,7 @@ An uncaught exception in a coroutine follows this flow:
3344
3321
7. If there is no parent scope, the exception falls into `globalScope`,
3345
3322
where the same rules apply as for a regular scope.
3346
3323
3347
-
<code>
3348
-
puml
3349
-
@startuml
3350
-
start
3351
-
:Unhandled Exception Occurred;
3352
-
if (Await keyword is used?) then (Yes)
3353
-
:Exception is propagated to await points;
3354
-
else (No)
3355
-
while (Scope exists?)
3356
-
:Exception is passed to Scope;
3357
-
if (Scope has an exception handler?) then (Yes)
3358
-
:Invoke exception handler;
3359
-
stop
3360
-
else (No)
3361
-
:Scope::cancel();
3362
-
endif
3363
-
if (Scope has responsibility points?) then (Yes)
3364
-
:All responsibility points receive the exception;
3365
-
stop
3366
-
endif
3367
-
if (Parent Scope exists?) then (Yes)
3368
-
:Pass exception to Parent Scope;
3369
-
else (No)
3370
-
:Pass exception to globalScope;
3371
-
break
3372
-
endif
3373
-
endwhile
3374
-
endif
3375
-
stop
3376
-
@enduml
3377
-
</code>
3324
+
{{ :rfc:true_async:exception_flow.svg |}}
3378
3325
3379
3326
**Example:**
3380
3327
@@ -3509,33 +3456,7 @@ If an exception occurs in a coroutine created within a **child Scope**,
3509
3456
it will be passed to the `setChildScopeExceptionHandler` handler and will not affect
3510
3457
the operation of the service as a whole.
3511
3458
3512
-
<code>
3513
-
puml
3514
-
@startuml
3515
-
actor Client
3516
-
participant "Service (Main Scope)" as Service
3517
-
participant "Request Handler (Child Scope)" as Handler
3518
-
3519
-
Client -> Service : New connection request
3520
-
Service -> Handler : Create child scope and spawn coroutine
3521
-
3522
-
loop For each request
3523
-
Client -> Handler : Send request
3524
-
Handler -> Client : Send response
3525
-
end
3526
-
3527
-
alt Exception in child scope
3528
-
Handler -> Service : Exception propagated to setChildScopeExceptionHandler
3529
-
note right: Exception is logged, service continues running
3530
-
end
3531
-
3532
-
alt Main scope cancelled
3533
-
Service -> Handler : Cancel all child scopes
3534
-
Handler -> Client : Disconnect
3535
-
end
3536
-
3537
-
@enduml
3538
-
</code>
3459
+
{{ :rfc:true_async:supervisor.svg |}}
3539
3460
3540
3461
=== Responsibility points ===
3541
3462
@@ -3856,7 +3777,7 @@ The `Coroutine` class implements methods for inspecting the state of a coroutine
3856
3777
| Method | Description |
3857
3778
| **`getSpawnFileAndLine():array`** | Returns an array of two elements: the file name and the line number where the coroutine was spawned. |
3858
3779
| **`getSpawnLocation():string`** | Returns a string representation of the location where the coroutine was spawned, typically in the format `"file:line"`. |
3859
-
| **`getSuspendFileAndLine():array`** | Returns an array of two elements: the file name and the line number where the coroutine was last suspended. If the coroutine has not been suspended, it may return `['',0]`. |
3780
+
| **`getSuspendFileAndLine():array`** | Returns an array of two elements: the file name and the line number where the coroutine was last suspended. If the coroutine has not been suspended, it may return empty string,0. |
3860
3781
| **`getSuspendLocation():string`** | Returns a string representation of the location where the coroutine was last suspended, typically in the format `"file:line"`. If the coroutine has not been suspended, it may return an empty string. |
3861
3782
| **`isSuspended():bool`** | Returns `true` if the coroutine has been suspended |
3862
3783
| **`isCancelled():bool`** | Returns `true` if the coroutine has been cancelled, otherwise `false`. |
@@ -3875,11 +3796,11 @@ The `Async\getCoroutines()` method returns an array of all coroutines in the app
0 commit comments