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

Commit 0a4d56d

Browse files
committed
+ base.rfc
1 parent aa17898 commit 0a4d56d

File tree

1 file changed

+20
-99
lines changed

1 file changed

+20
-99
lines changed

base.rfc

Lines changed: 20 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -450,46 +450,23 @@ will be thrown from the suspension point.
450450

451451
=== Coroutine Lifecycle ===
452452

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 |}}
477454

478455
This state diagram illustrates the lifecycle of a coroutine, showing how it transitions through various states during its execution:
479456

480457
**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.
487464

488465
**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**.
493470

494471
=== `Coroutine` state check methods ===
495472

@@ -3344,37 +3321,7 @@ An uncaught exception in a coroutine follows this flow:
33443321
7. If there is no parent scope, the exception falls into `globalScope`,
33453322
where the same rules apply as for a regular scope.
33463323

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 |}}
33783325

33793326
**Example:**
33803327

@@ -3509,33 +3456,7 @@ If an exception occurs in a coroutine created within a **child Scope**,
35093456
it will be passed to the `setChildScopeExceptionHandler` handler and will not affect
35103457
the operation of the service as a whole.
35113458

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 |}}
35393460

35403461
=== Responsibility points ===
35413462

@@ -3856,7 +3777,7 @@ The `Coroutine` class implements methods for inspecting the state of a coroutine
38563777
| Method | Description |
38573778
| **`getSpawnFileAndLine():array`** | Returns an array of two elements: the file name and the line number where the coroutine was spawned. |
38583779
| **`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. |
38603781
| **`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. |
38613782
| **`isSuspended():bool`** | Returns `true` if the coroutine has been suspended |
38623783
| **`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
38753796

38763797
==== Prototypes ====
38773798

3878-
* [Async functions](./examples/Async/Async.php)
3879-
* [Coroutine](./examples/Async/Coroutine.php)
3880-
* [Coroutine Context](./examples/Async/Context.php)
3881-
* [Coroutine Scope](./examples/Async/Scope.php)
3882-
* [Task Group](./examples/Async/TaskGroup.php)
3799+
* [Async functions](https://github.com/EdmondDantes/php-true-async-rfc/tree/main/examples/Async/Async.php)
3800+
* [Coroutine](https://github.com/EdmondDantes/php-true-async-rfc/tree/main/examples/Async/Coroutine.php)
3801+
* [Coroutine Context](https://github.com/EdmondDantes/php-true-async-rfc/tree/main/examples/Async/Context.php)
3802+
* [Coroutine Scope](https://github.com/EdmondDantes/php-true-async-rfc/tree/main/examples/Async/Scope.php)
3803+
* [Task Group](https://github.com/EdmondDantes/php-true-async-rfc/tree/main/examples/Async/TaskGroup.php)
38833804

38843805
===== Backward Incompatible Changes =====
38853806

@@ -3919,7 +3840,7 @@ No new constants are introduced.
39193840

39203841
==== php.ini Defaults ====
39213842

3922-
No changes are made to the default settings.
3843+
* async.zombie_coroutine_timeout - default 5 seconds
39233844

39243845
===== Open Issues =====
39253846
None.

0 commit comments

Comments
 (0)