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


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.

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


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