No matching definitions.

tur/taskgroup

stdlib/taskgroup.tur

structured concurrency with scoped TaskGroup.

Since: Phase T22

defopaque linear

TaskGroup

(TaskGroup)
defopaque

TaskHandle

(TaskHandle)
defn

task-group-new

(task-group-new :)

create a new empty TaskGroup.

A TaskGroup handle to the TaskGroupBlock.

(let [g (task-group-new)] ...)  ; => TaskGroup

Since: Phase T22

defn

fiber-cancelled?

(fiber-cancelled? :)

check whether the current fiber has been cancelled.

true if the thread-local cancelled flag is set; false otherwise.

(if (fiber-cancelled?) ...)  ; => bool

Since: Phase T22

defn

task-group-cancelled?

(task-group-cancelled? [^borrow group : TaskGroup] :)

check whether a specific task group has been cancelled.

grouptask group handle returned by task-group-new

true if the group's cancelled flag is set; false otherwise.

(if (task-group-cancelled? g) ...)  ; => bool

Since: Phase T22

defn

task-group-should-exit?

(task-group-should-exit? [^borrow group : TaskGroup] :)

return true if the current task should stop, checking both fiber and group cancellation.

grouptask group handle returned by task-group-new

true if either the current fiber or the group has been cancelled.

(if (task-group-should-exit? g) ...)  ; => bool

Since: Phase T22

defn

fiber-should-exit?

(fiber-should-exit? :)

check whether the current fiber should exit (without group context).

true if the thread-local cancelled flag is set.

(if (fiber-should-exit?) ...)  ; => bool

Since: Phase T22

defn

task-group-done?

(task-group-done? [^borrow group : TaskGroup] :)

check whether all tasks in the group have completed.

grouptask group handle returned by task-group-new

true if all spawned tasks have called task-group-task-done.

(if (task-group-done? g) ...)  ; => bool

Since: Phase T22

defn

task-group-task-done

(task-group-task-done [^borrow group : TaskGroup] :)

signal that the calling task has completed; must be called by each spawned task.

grouptask group handle returned by task-group-new
(task-group-task-done g)

Since: Phase T22

defn

task-group-wait

(task-group-wait [^borrow group : TaskGroup] :)

block until all tasks in the group have completed.

grouptask group handle returned by task-group-new
(task-group-wait g)

Since: Phase T22

defn

task-group-cancel

(task-group-cancel [^borrow group : TaskGroup] :)

cooperatively cancel all tasks in the group (reason: manual).

grouptask group handle returned by task-group-new
(task-group-cancel g)

Since: Phase T22

defn

task-group-cancel-with-reason

(task-group-cancel-with-reason [^borrow group : TaskGroup reason : int] :)

cancel all tasks in the group with a specific reason code.

grouptask group handle returned by task-group-new
reasoncancel reason: 0=manual, 1=panic, 2=timeout, 3=error
(task-group-cancel-with-reason g 2)

Since: Phase T22

defn

task-group-cancel-panic

(task-group-cancel-panic [^borrow group : TaskGroup] :)

cancel the group with reason 1 (panic).

grouptask group handle returned by task-group-new
(task-group-cancel-panic g)

Since: Phase T22

defn

task-group-cancel-timeout

(task-group-cancel-timeout [^borrow group : TaskGroup] :)

cancel the group with reason 2 (timeout).

grouptask group handle returned by task-group-new
(task-group-cancel-timeout g)

Since: Phase T22

defn

task-group-cancel-error

(task-group-cancel-error [^borrow group : TaskGroup] :)

cancel the group with reason 3 (error).

grouptask group handle returned by task-group-new
(task-group-cancel-error g)

Since: Phase T22

defn

task-group-cancel-reason

(task-group-cancel-reason [^borrow group : TaskGroup] :)

return the reason code why the group was cancelled.

grouptask group handle returned by task-group-new

An int reason code: 0=manual, 1=panic, 2=timeout, 3=error.

(task-group-cancel-reason g)  ; => int

Since: Phase T22

defn

task-group-spawn

(task-group-spawn [^borrow group : TaskGroup f ptr<void>] :)

spawn a fiber into the task group and return its handle.

grouptask group handle returned by task-group-new
fzero-argument fiber entry-point function pointer

A ptr<void> fiber handle that can be passed to task-group-join.

(let [h (task-group-spawn g my-fiber-fn)] ...)  ; => ptr<void>

Since: Phase T22

defn

task-group-join

(task-group-join [^borrow group : TaskGroup handle : TaskHandle] :)

wait for a specific spawned fiber to complete.

grouptask group handle returned by task-group-new
handlefiber handle returned by task-group-spawn
(task-group-join g h)

Since: Phase T22

defn

task-handle-done?

(task-handle-done? [handle : TaskHandle] :)

non-blocking check whether a specific spawned fiber has completed.

handlefiber handle returned by task-group-spawn

true if the fiber is done or the handle is NULL.

(if (task-handle-done? h) ...)  ; => bool

Since: Phase T22

defn

task-group-free

(task-group-free [group : TaskGroup] :)

destroy a task group and release its memory.

grouptask group handle returned by task-group-new
(task-group-free g)

Since: Phase T22

defmacro

task-group-with

(task-group-with [group & body])
defmacro

task-group-with-timeout

(task-group-with-timeout [group ms & body])
defn

spawn-timeout-thread-fn

(spawn-timeout-thread-fn [raw ptr<void>] :)

pthread body for spawn-timeout-thread. INTERNAL.

defn

spawn-timeout-thread

(spawn-timeout-thread [^borrow group : TaskGroup ms : int] :)

spawn a background thread that cancels the group after ms milliseconds.

grouptask group handle returned by task-group-new
msdelay in milliseconds before the group is cancelled

A ptr<void> thread handle (detached; free with join-timeout-thread).

Since: Phase T22

defn

join-timeout-thread

(join-timeout-thread [t ptr<void>] :)

free the handle of a detached timeout thread.

tthread handle returned by spawn-timeout-thread
(join-timeout-thread t)

Since: Phase T22

defmacro

task-group-with-cancellation

(task-group-with-cancellation [group & body])
defn

task-group-spawn-async

(task-group-spawn-async [^borrow group : TaskGroup f ptr<void>] :)

spawn an async computation into a task group and return a Future.

grouptask group handle returned by task-group-new
fno-argument function returning int64_t to run as a fiber

A ptr<void> Future fulfilled with f's return value when the fiber completes.

(let [fut (task-group-spawn-async g my-thunk)] (await fut))  ; => ptr<void>

Since: Phase T22

defmacro

task-group-async

(task-group-async [group async-thunk])
Internal definitions
__fiber_set_cancelled-- set the current fiber's cancelled flag (internal use only).
__tg-async-entry-- internal fiber entry point for task-group-spawn-async (internal use only).