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
ContextGroupmanages multiple current scheduler contexts through one group handle.- Default construction and
INITcreate an empty group. spawnadds one member and returns no per-member handle.- Grouped callables use output schema
(); member outputs are neither retained nor exposed. - 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 object.wait
(--) Waits until the group becomes empty.Waiting and cancellation semantics
- If the current context is already canceled when
waitbegins,waitfirst requests cancellation of every current member and then waits until the group becomes empty. - If the current context is not canceled when
waitbegins, 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
spawncalls create later members that are not implicitly canceled by an earliercancelcall.
Examples
Wait on an empty group
"String" use
"control" use
"sync/ContextGroup" use
{} Int32 {} [
group: ContextGroup;
@group.wait
("done" LF) printList
0
] "main" exportFunction
Expected Output
done
Spawn two contexts and wait for the group
"String" use
"control" use
"sync/ContextGroup" 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
"String" use
"control" use
"sync/ContextGroup" use
"sync/sync" 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.