From 2b9ef4196e3ce6277b7a188296bc93d4a145e49a Mon Sep 17 00:00:00 2001 From: Sam Pillsworth Date: Wed, 28 Aug 2024 16:19:32 -0400 Subject: [PATCH 1/2] splice the lifecycle diagrams into supervisor docs --- docs/std/supervisor.md | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/std/supervisor.md b/docs/std/supervisor.md index 5b0a688bc6..27253cf0bc 100644 --- a/docs/std/supervisor.md +++ b/docs/std/supervisor.md @@ -11,6 +11,38 @@ title: Supervisor `Spawn[F]#background`: ties the lifecycle of the spawned fiber to that of the fiber that invoked `background` +The following diagrams illustrate the lifecycle of the spawned fiber in both cases. +In each example, some fiber A is spawning another fiber B. +Each box represents the lifecycle of a fiber. +If a box is enclosed within another box, it means that the lifecycle of the former is confined within the lifecycle of the latter. +In other words, if an outer fiber terminates, the inner fibers are guaranteed to be terminated as well. + +`Spawn[F]#start`: +``` +Fiber A lifecycle ++---------------------+ +| | | ++-----------------|---+ + | + |A starts B +Fiber B lifecycle | ++-----------------|---+ +| + | ++---------------------+ +``` + +`Spawn[F]#background:` +``` +Fiber A lifecycle ++------------------------+ +| | | +| Fiber B lifecycle |A starts B +| +------------------|-+ | +| | | | | +| +--------------------+ | ++------------------------+ +``` + But what if we want to spawn a fiber that should outlive the scope that created it, but we still want to control its lifecycle? @@ -31,6 +63,25 @@ object Supervisor { Any fibers created via the supervisor will be finalized when the supervisor itself is finalized via `Resource#use`. +The lifecycle of fibers spawned with `Supervisor` can be illustrated in the same style as above: + +``` +Supervisor lifecycle ++---------------------+ +| Fiber B lifecycle | +| +-----------------+ | +| | + | | +| +---------------|-+ | ++-----------------|---+ + | + | A starts B +Fiber A lifecycle | ++-----------------|---+ +| | | ++---------------------+ +``` + + There are two finalization strategies according to the `await` parameter of the constructor: - `true` - wait for the completion of the active fibers - `false` - cancel the active fibers From 690a4cb8c08d10fec57c79cdc17881ee326d8b07 Mon Sep 17 00:00:00 2001 From: Sam Pillsworth Date: Wed, 28 Aug 2024 16:26:56 -0400 Subject: [PATCH 2/2] move colon --- docs/std/supervisor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/std/supervisor.md b/docs/std/supervisor.md index 27253cf0bc..921b54c3f0 100644 --- a/docs/std/supervisor.md +++ b/docs/std/supervisor.md @@ -31,7 +31,7 @@ Fiber B lifecycle | +---------------------+ ``` -`Spawn[F]#background:` +`Spawn[F]#background`: ``` Fiber A lifecycle +------------------------+