Skip to content

mizu_collect_any() waits on several task handles at once and returns as soon as any of them reaches a terminal state — result published, error raised, cancelled, or its worker died. Among handles already terminal, the earliest in tasks is reported. The wait parks on the submitter's single parker: any publishing worker wakes it directly, with no polling. For the whole set at once, mizu_collect_all() waits until every task is terminal and returns all results in input order.

Usage

mizu_collect_any(tasks, timeout = Inf)

Arguments

tasks

a non-empty list of task handles from mizu_submit() on the same pool handle.

timeout

seconds to wait for a task to reach a terminal state before the call returns the mizu_timeout sentinel. Inf (the default) waits indefinitely; 0 does not wait.

Value

For a published result, list(index = i, value = v): the 1-based position of the task in tasks and its value. Otherwise the mizu_timeout sentinel.

Outcomes

As for mizu_collect(), but attributed to a handle by position:

outcomesurfaced asclass
result publishedlist(index, value), returned—
nothing terminal within timeoutsentinel, returnedc("mizu_timeout", "mizu_sentinel")
task raised an errorre-signalled with an index fieldthe condition classes of the task itself
cancelled, or pool stoppedraised with an index fieldmizu_error_cancelled
executing worker diedraised with an index fieldmizu_error_worker_died

The index field of a raised condition is the 1-based position of the task in tasks (conditions are lists, so the field travels in place). The reported handle is consumed; the remaining handles stay valid and collectible.

Examples

if (FALSE) { # interactive()
p <- mizu_pool(2L)
slow <- mizu_submit(p, { Sys.sleep(0.5); "slow" })
fast <- mizu_submit(p, "fast")
# completion order, not submission order
mizu_collect_any(list(slow, fast), timeout = 30)
mizu_collect(slow, timeout = 30)
mizu_pool_stop(p)
}