tur/future
future-cell-new
(future-cell-new :ptr<void>)
allocate and initialise a shared FutureCell (mutex, condvar, unset).
Since: Phase T20-C
future-cell-free
(future-cell-free [cell :ptr<void>] :nil)
destroy the mutex/condvar and free a FutureCell.
| cell | FutureCell pointer from future-cell-new |
Since: Phase T20-C
promise-new
(promise-new :ptr<void>)
allocate a new unsettled Promise/Future shared cell.
Since: Phase T20-C
promise-of-cell
(promise-of-cell [cell :ptr<void>] :ptr<void>)
return the Promise handle for a FutureCell (identity; for API symmetry).
| cell | FutureCell pointer from promise-new |
Since: Phase T20-C
future-of-cell
(future-of-cell [cell :ptr<void>] :ptr<void>)
return the Future handle for a FutureCell (identity; for API symmetry).
| cell | FutureCell pointer from promise-new |
Since: Phase T20-C
promise-pair
(promise-pair [cell :ptr<void>])
expand to a (Promise Future) pair list from a single shared cell.
| cell | FutureCell pointer from promise-new |
Since: Phase T20-C
promise-fulfill
(promise-fulfill [p :ptr<void> v :int] :nil)
settle a promise with a successful value; wakes all future waiters.
| p | Promise (FutureCell) pointer | |
| v | fulfillment value |
Since: Phase T20-C
promise-fail
(promise-fail [p :ptr<void> e :int] :nil)
settle a promise with an error code; wakes all future waiters.
| p | Promise (FutureCell) pointer | |
| e | error/exception code |
Since: Phase T20-C
promise-free
(promise-free [p :ptr<void>] :nil)
free a promise and its shared FutureCell.
| p | Promise pointer from promise-new |
Since: Phase T20-C
future-done?
(future-done? [f :ptr<void>] :bool)
non-blocking check: return true if the future has been settled.
| f | Future (FutureCell) pointer |
Since: Phase T20-C
future-get
(future-get [f :ptr<void>] :ptr<void>)
block until the future is settled; return a heap-allocated Result struct.
| f | Future (FutureCell) pointer |
Since: Phase T20-C
future-free
(future-free [f :ptr<void>] :nil)
free a future and its shared FutureCell.
| f | Future pointer from promise-new / future-of-cell |
Since: Phase T20-C
future-of
(future-of [v :int] :ptr<void>)
create a pre-fulfilled future holding value v.
| v | value the future should carry |
Since: Phase T20-C
future-error-of
(future-error-of [e :int] :ptr<void>)
create a pre-rejected future with error code e.
| e | error/exception code |
Since: Phase T20-C
future-cancel
(future-cancel [f :ptr<void>] :nil)
cancel a future if not yet settled; sets error code -2 (TUR_FUTURE_CANCELLED).
| f | Future (FutureCell) pointer |
Since: Phase T20-C
future-cancelled?
(future-cancelled? [f :ptr<void>] :bool)
return true if the future was cancelled (exn == -2).
| f | Future (FutureCell) pointer |
Since: Phase T20-C
future-map
(future-map [f :ptr<void> fn :ptr<void>] :ptr<void>)
map fn over a fulfilled future value; propagate rejection unchanged.
| f | source Future pointer | |
| fn | function pointer (int64_t -> int64_t) applied to the fulfilled value |
Since: Phase T20-C
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>.
| f | source Future pointer | |
| fn | function pointer (int64_t -> ptr<void>) producing the next Future |
Since: Phase T20-C
future-race
(future-race [fa :ptr<void> fb :ptr<void>] :ptr<void>)
race two futures; return a new future settled by whichever finishes first.
| fa | first Future pointer | |
| fb | second Future pointer |
Since: Phase T20-C
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.
| fa | first Future pointer | |
| fb | second Future pointer |
Since: Phase T20-C
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.
| fa | first Future pointer | |
| fb | second Future pointer |
Since: Phase T20-C
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.
| fa | first Future pointer | |
| fb | second Future pointer |
Since: Phase T20-C
tuple-first
(tuple-first [tup :ptr<void>] :int)
read the first element of a TurTuple2 returned by future-join.
| tup | TurTuple2 pointer from the ok value of a future-join result |
Since: Phase T20-C
tuple-second
(tuple-second [tup :ptr<void>] :int)
read the second element of a TurTuple2 returned by future-join.
| tup | TurTuple2 pointer from the ok value of a future-join result |
Since: Phase T20-C
tuple-free
(tuple-free [tup :ptr<void>] :nil)
free a TurTuple2 allocated by future-join.
| tup | TurTuple2 pointer to free |
Since: Phase T20-C
promise-new-pair
(promise-new-pair :ptr<void>)
allocate a new unsettled Promise/Future shared cell (alias for promise-new).
Since: Phase T20-C
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.
| futures | pointer to an array of FutureCell* (ptr<void>[n]) | |
| n | number of futures in the array |
Since: Phase T20-C
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.
| futures | pointer to an array of FutureCell* (ptr<void>[n]) | |
| n | number of futures in the array |
Since: Phase T20-C
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.
| futures | pointer to an array of FutureCell* (ptr<void>[n]) | |
| n | number of futures in the array |
Since: Phase T20-C
future-timeout
(future-timeout [ms :int] :ptr<void>)
create a future that settles with error -1 after ms milliseconds.
| ms | timeout duration in milliseconds |
Since: Phase T20-C
future-with-timeout
(future-with-timeout [f :ptr<void> ms :int] :ptr<void>)
race a future against a timeout of ms milliseconds.
| f | source Future pointer | |
| ms | timeout in milliseconds; on expiry the result is rejected with exn = -1 |
Since: Phase T20-C