Futurama is a Clojure library for more deeply integrating async abstractions in the Clojure and JVM ecosystem with Clojure.
async and thread blocks are dispatched over an internal thread pool,
which defaults to using the ForkJoinPool/commonPool. They work very
similarly to core.async go blocks and thread blocks. Notable different
ways are that, async and thread blocks will return Throwable values when
exceptions are uncaught, and that taking a value from an async result
using !<! or !<!! will reduce nested async values to a single result.
The dynamic variables *async-factory* and *thread-factory* can be bound
to control which async result type is returned when the async or thread
macros are used. If an *async-factory* is bound but no *thread-factory*,
then calls to thread will use the *async-factory*, or if a factory is not
defined then the default async-promise-factory will be used instead.
Possible factories supported are:
async-channel-factory: creates a core.async channel result, with a buffer of size 1.async-promise-factory: creates a core.async promise-channel result.async-deferred-factory: creates a manifold deferred result.async-future-factory: creates a CompletableFuture result.Use the Java system property futurama.executor-factory
to specify a function that will provide ExecutorServices for
application-wide use by futurama in lieu of its defaults.
To ensure that futurama uses the same thread pool as core.async,
you can set the property to the value clojure.core.async.impl.dispatch/executor-for.
The property value should name a fully qualified var. The function
will be passed a keyword indicating the context of use of the
executor, and should return either an ExecutorService, or nil to
use the default. Results per keyword will be cached and used for
the remainder of the application.
Possible context arguments are:
:io - used for :io workloads, default workload for async dispatch, use via (thread :io ...) or (async :io ...).
:mixed - used for :mixed workloads, default workload for thread dispatch.
:compute - used for :compute workloads, use via (thread :compute ...) or (async :compute ...).
The set of contexts may grow in the future so the function should return nil for unexpected contexts.
Copied from core.async, because this is super useful:
Set Java system property clojure.core.async.go-checking to true
to validate async blocks do not invoke core.async blocking operations.
Property is read once, at namespace load time. Recommended for use
primarily during development. Invalid blocking calls will throw in
go block threads - use Thread.setDefaultUncaughtExceptionHandler()
to catch and handle.
Futurama is a Clojure library for more deeply integrating async abstractions in the Clojure and JVM ecosystem with Clojure. async and thread blocks are dispatched over an internal thread pool, which defaults to using the `ForkJoinPool/commonPool`. They work very similarly to core.async go blocks and thread blocks. Notable different ways are that, async and thread blocks will return Throwable values when exceptions are uncaught, and that taking a value from an async result using `!<!` or `!<!!` will reduce nested async values to a single result. The dynamic variables `*async-factory*` and `*thread-factory*` can be bound to control which async result type is returned when the `async` or `thread` macros are used. If an `*async-factory*` is bound but no `*thread-factory*`, then calls to `thread` will use the `*async-factory*`, or if a factory is not defined then the default `async-promise-factory` will be used instead. Possible factories supported are: - `async-channel-factory`: creates a core.async channel result, with a buffer of size 1. - `async-promise-factory`: creates a core.async promise-channel result. - `async-deferred-factory`: creates a manifold deferred result. - `async-future-factory`: creates a CompletableFuture result. Use the Java system property `futurama.executor-factory` to specify a function that will provide ExecutorServices for application-wide use by futurama in lieu of its defaults. To ensure that futurama uses the same thread pool as core.async, you can set the property to the value `clojure.core.async.impl.dispatch/executor-for`. The property value should name a fully qualified var. The function will be passed a keyword indicating the context of use of the executor, and should return either an ExecutorService, or nil to use the default. Results per keyword will be cached and used for the remainder of the application. Possible context arguments are: :io - used for :io workloads, default workload for `async` dispatch, use via `(thread :io ...)` or `(async :io ...)`. :mixed - used for :mixed workloads, default workload for `thread` dispatch. :compute - used for :compute workloads, use via `(thread :compute ...)` or `(async :compute ...)`. The set of contexts may grow in the future so the function should return nil for unexpected contexts. Copied from core.async, because this is super useful: Set Java system property `clojure.core.async.go-checking` to true to validate async blocks do not invoke core.async blocking operations. Property is read once, at namespace load time. Recommended for use primarily during development. Invalid blocking calls will throw in go block threads - use Thread.setDefaultUncaughtExceptionHandler() to catch and handle.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |