tur/future

stdlib/future.tur
defn

future-cell-new

(future-cell-new :ptr<void>)

allocate and initialise a shared FutureCell (mutex, condvar, unset).

Since: Phase T20-C

defn

future-cell-free

(future-cell-free [cell :ptr<void>] :nil)

destroy the mutex/condvar and free a FutureCell.

cellFutureCell pointer from future-cell-new

Since: Phase T20-C

defn

promise-new

(promise-new :ptr<void>)

allocate a new unsettled Promise/Future shared cell.

Since: Phase T20-C

defn

promise-of-cell

(promise-of-cell [cell :ptr<void>] :ptr<void>)

return the Promise handle for a FutureCell (identity; for API symmetry).

cellFutureCell pointer from promise-new

Since: Phase T20-C

defn

future-of-cell

(future-of-cell [cell :ptr<void>] :ptr<void>)

return the Future handle for a FutureCell (identity; for API symmetry).

cellFutureCell pointer from promise-new

Since: Phase T20-C

defmacro

promise-pair

(promise-pair [cell :ptr<void>])

expand to a (Promise Future) pair list from a single shared cell.

cellFutureCell pointer from promise-new

Since: Phase T20-C

defn

promise-fulfill

(promise-fulfill [p :ptr<void> v :int] :nil)

settle a promise with a successful value; wakes all future waiters.

pPromise (FutureCell) pointer
vfulfillment value

Since: Phase T20-C

defn

promise-fail

(promise-fail [p :ptr<void> e :int] :nil)

settle a promise with an error code; wakes all future waiters.

pPromise (FutureCell) pointer
eerror/exception code

Since: Phase T20-C

defn

promise-free

(promise-free [p :ptr<void>] :nil)

free a promise and its shared FutureCell.

pPromise pointer from promise-new

Since: Phase T20-C

defn

future-done?

(future-done? [f :ptr<void>] :bool)

non-blocking check: return true if the future has been settled.

fFuture (FutureCell) pointer

Since: Phase T20-C

defn

future-get

(future-get [f :ptr<void>] :ptr<void>)

block until the future is settled; return a heap-allocated Result struct.

fFuture (FutureCell) pointer

Since: Phase T20-C

defn

future-free

(future-free [f :ptr<void>] :nil)

free a future and its shared FutureCell.

fFuture pointer from promise-new / future-of-cell

Since: Phase T20-C

defn

future-of

(future-of [v :int] :ptr<void>)

create a pre-fulfilled future holding value v.

vvalue the future should carry

Since: Phase T20-C

defn

future-error-of

(future-error-of [e :int] :ptr<void>)

create a pre-rejected future with error code e.

eerror/exception code

Since: Phase T20-C

defn

future-cancel

(future-cancel [f :ptr<void>] :nil)

cancel a future if not yet settled; sets error code -2 (TUR_FUTURE_CANCELLED).

fFuture (FutureCell) pointer

Since: Phase T20-C

defn

future-cancelled?

(future-cancelled? [f :ptr<void>] :bool)

return true if the future was cancelled (exn == -2).

fFuture (FutureCell) pointer

Since: Phase T20-C

defn

future-map

(future-map [f :ptr<void> fn :ptr<void>] :ptr<void>)

map fn over a fulfilled future value; propagate rejection unchanged.

fsource Future pointer
fnfunction pointer (int64_t -> int64_t) applied to the fulfilled value

Since: Phase T20-C

defn

future-then

(future-then [f :ptr<void> fn :ptr<void>] :ptr<void>)

flat-map fn over a future; fn must return a new Future ptr<void>.

fsource Future pointer
fnfunction pointer (int64_t -> ptr<void>) producing the next Future

Since: Phase T20-C

defn

future-race

(future-race [fa :ptr<void> fb :ptr<void>] :ptr<void>)

race two futures; return a new future settled by whichever finishes first.

fafirst Future pointer
fbsecond Future pointer

Since: Phase T20-C

defn

future-all2

(future-all2 [fa :ptr<void> fb :ptr<void>] :ptr<void>)

await both futures; settle ok with fa's value only if both succeed.

fafirst Future pointer
fbsecond Future pointer

Since: Phase T20-C

defn

future-any2

(future-any2 [fa :ptr<void> fb :ptr<void>] :ptr<void>)

return a future settled by the first fulfilled future; both rejecting yields fb's error.

fafirst Future pointer
fbsecond Future pointer

Since: Phase T20-C

defn

future-join

(future-join [fa :ptr<void> fb :ptr<void>] :ptr<void>)

await both futures and produce a new future holding a TurTuple2 of their values.

fafirst Future pointer
fbsecond Future pointer

Since: Phase T20-C

defn

tuple-first

(tuple-first [tup :ptr<void>] :int)

read the first element of a TurTuple2 returned by future-join.

tupTurTuple2 pointer from the ok value of a future-join result

Since: Phase T20-C

defn

tuple-second

(tuple-second [tup :ptr<void>] :int)

read the second element of a TurTuple2 returned by future-join.

tupTurTuple2 pointer from the ok value of a future-join result

Since: Phase T20-C

defn

tuple-free

(tuple-free [tup :ptr<void>] :nil)

free a TurTuple2 allocated by future-join.

tupTurTuple2 pointer to free

Since: Phase T20-C

defn

promise-new-pair

(promise-new-pair :ptr<void>)

allocate a new unsettled Promise/Future shared cell (alias for promise-new).

Since: Phase T20-C

defn

future-race-n

(future-race-n [futures :ptr<void> n :int] :ptr<void>)

race an array of n futures; return a new future settled by the first to finish.

futurespointer to an array of FutureCell* (ptr<void>[n])
nnumber of futures in the array

Since: Phase T20-C

defn

future-all-n

(future-all-n [futures :ptr<void> n :int] :ptr<void>)

await all n futures; settle ok (value 0) only if every future succeeds.

futurespointer to an array of FutureCell* (ptr<void>[n])
nnumber of futures in the array

Since: Phase T20-C

defn

future-any-n

(future-any-n [futures :ptr<void> n :int] :ptr<void>)

return a future settled by the first successfully fulfilled future in the array.

futurespointer to an array of FutureCell* (ptr<void>[n])
nnumber of futures in the array

Since: Phase T20-C

defn

future-timeout

(future-timeout [ms :int] :ptr<void>)

create a future that settles with error -1 after ms milliseconds.

mstimeout duration in milliseconds

Since: Phase T20-C

defn

future-with-timeout

(future-with-timeout [f :ptr<void> ms :int] :ptr<void>)

race a future against a timeout of ms milliseconds.

fsource Future pointer
mstimeout in milliseconds; on expiry the result is rejected with exn = -1

Since: Phase T20-C