General concurrency facilities, futures, promises.

default-future-executor

Available since version 1.0 (view source)

not referred automatically

VAR of type clojure.lang.Var

A dynamic var holding default future executor.

deliver!

Available since version 1.0 (view source)

Usage:
  • (deliver! promise val)

Type signature:
  • ((I IReference IBlockingReference IPending) ⨯ Any) → nil

Delivers the supplied val to the promise, releasing any pending derefs. A subsequent call to deliver on a promise will have no effect.

execute

Available since version 1.0 (view source)

Usage:
  • (execute executor f)

Type signature:
  • (IExecutor ⨯ Function) → nil

Executes function f with executor. Returns nil.

See also: submit, IExecutor

future

Available since version 1.0 (view source)

MACRO (future & body)

Takes a body of expressions and yields an IFuture object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block, unless the variant of deref with timeout is used.

If first form in a body is a map, uses it as a config map. Current config keys are:

  • :executor - A ITaskExecutor to be used to execute future tasks.

See also: future-call

future-call

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (future-call f)

  • (future-call executor f)

Type signatures:
  • (Function) → IFuture

  • (ITaskExecutor ⨯ Function) → IFuture

Takes a function of no args and yields an IFuture object that will invoke the function in a given executor (in another thread), and will cache the result and return it on all subsequent calls to deref/@. Uses default-future-executor if executor is not specified. If the computation has not yet finished, calls to deref/@ will block, unless the variant of deref with timeout is used.

future?

Available since version 1.0 (view source)

Usage:
  • (future? x)

Type signature: Predicate

Returns true if object x satisfies IFuture protocol, false otherwise.

See also: IFuture, future, future-call

locking

Available since version 1.0 (alias of clojure.core/locking)

MACRO (locking x & body)

Executes body in an implicit do, while holding the monitor of x. Will release the monitor of x in all circumstances.

promise

Available since version 1.0 (alias of clojure.core/promise)

Usage:
  • (promise)

Type signature:
  • () → (I IReference IBlockingReference IPending)

Returns a promise object that can be read with deref/@, and set, once only, with deliver. Calls to deref/@ prior to delivery will block, unless the variant of deref with timeout is used. All subsequent derefs will return the same delivered value without blocking.

submit

Available since version 1.0 (view source)

Usage:
  • (submit executor executable)

Type signature:
  • (ITaskExecutor ⨯ Function) → IFuture

Submits a function f for execution and returns an IFuture representing that task.

See also: execute, ITaskExecutor