Group handle for spawned contexts with shared waiting and cancellation. A ContextGroup manages completion for multiple contexts, returns no per-context handle, and exposes no per-context outputs.
Group and completion model
ContextGroup manages multiple current scheduler contexts through one group handle.
- Default construction and
INIT create an empty group.
spawn adds one member and returns no per-member handle.
- Grouped callables use output schema
(); member outputs are neither retained nor exposed.
cancel only requests cancellation of the current members and returns immediately.
wait returns only when the group becomes empty.
- Destroying a non-empty group waits until all current members finish and then releases the group state.
Methods
INIT |
(--) |
Creates an empty group. |
spawn |
(callable --) |
Schedules one callable as a new member of the group. The callable returns no value. |
wait |
(--) |
Waits until the group becomes empty. |
Remarks
- Calling
wait on an empty group returns immediately.
cancel |
(--) |
Requests cancellation of every current member and returns immediately. |
Remarks
- Only members that are current when
cancel is called receive that request.
Waiting and cancellation semantics
wait on an empty group returns immediately.
- If the current context is already canceled when
wait begins, wait first requests cancellation of every current member and then waits until the group becomes empty.
- If the current context is not canceled when
wait begins, later cancellation of that waiting context requests cancellation of every current member.
- Only one unfinished wait may target the same non-empty group at a time.
- Later
spawn calls create later members that are not implicitly canceled by an earlier cancel call.
Examples
Wait on an empty group
"sync/ContextGroup" use
"String" use
"control" use
{} Int32 {} [
group: ContextGroup;
@group.wait
("done" LF) printList
0
] "main" exportFunction
Expected Output
done
Spawn two contexts and wait for the group
"sync/ContextGroup" use
"String" use
"control" use
{} Int32 {} [
group: ContextGroup;
[("one" LF) printList] @group.spawn
[("two" LF) printList] @group.spawn
@group.wait
("done" LF) printList
0
] "main" exportFunction
Expected Output
one
two
done
Cancel current members
"sync/ContextGroup" use
"sync/sync" use
"String" use
"control" use
{} Int32 {} [
group: ContextGroup;
[10.0r64 sleepFor canceled? [
("canceled" LF) printList
] [
("not-canceled" LF) printList
] if] @group.spawn
[10.0r64 sleepFor canceled? [
("canceled" LF) printList
] [
("not-canceled" LF) printList
] if] @group.spawn
@group.cancel
@group.wait
("done" LF) printList
0
] "main" exportFunction
Expected Output
canceled
canceled
done
See also
- sync/Context: Spawned context handle with waiting, output retrieval, and cancellation.
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.
- sync/Event: Persistent event state with clear, set, wait, wake, and wakeOne.