Async/await-style concurrency and async iteration built on core.async.
Choosing an execution: async: use for async control flow, polling, and small or short computations; work may park, but must not block compute: use for heavy or long-running computation; do not block blocking: use for blocking I/O and other operations that block the current thread Executor implementations vary with the core.async version and JVM configuration.
Core terms: settle(d): deliver one result and close the channel; settling nil closes without delivering because core.async channels cannot contain nil fulfill(ed): deliver a value without closing the channel, leaving it open for additional values promise-chan: a single-result core.async channel used for async-style execution results and cooperative cancellation producer settlement: async, blocking, and compute wait for one returned promise-like single-result value before settling their own result; returned multi-value source channels remain channel values ownership: starting async, blocking, or compute inside a running execution creates an owned child unless started inside detach; ending the parent cancels unfinished owned children observation: awaiting or composing already-started work borrows it without transferring ownership or cancelling it async source: async-generator returns a cold, lifecycle-aware multi-value channel; consumption starts its producer in the consuming scope, and channel close or a nil take means done
Async/await-style concurrency and async iteration built on core.async.
Choosing an execution:
async: use for async control flow, polling, and small or short computations; work may park, but must not block
compute: use for heavy or long-running computation; do not block
blocking: use for blocking I/O and other operations that block the current thread
Executor implementations vary with the core.async version and JVM configuration.
Core terms:
settle(d): deliver one result and close the channel; settling nil closes without delivering because core.async channels cannot contain nil
fulfill(ed): deliver a value without closing the channel, leaving it open for additional values
promise-chan: a single-result core.async channel used for async-style execution results and cooperative cancellation
producer settlement: async, blocking, and compute wait for one returned promise-like single-result value before settling their own result; returned multi-value source channels remain channel values
ownership: starting async, blocking, or compute inside a running execution creates an owned child unless started inside detach; ending the parent cancels unfinished owned children
observation: awaiting or composing already-started work borrows it without transferring ownership or cancelling it
async source: async-generator returns a cold, lifecycle-aware multi-value channel; consumption starts its producer in the consuming scope, and channel close or a nil take means done(->promise-chan this)Coerce to a promise-chan if possible, otherwise is just a pass-through.
Currently supports:
Coerce to a promise-chan if possible, otherwise is just a pass-through. Currently supports: * Future * CompletableFuture * IBlockingDeref
(ado & exprs)Asynchronous do. Execute expressions one after the other, awaiting the result of each one before moving on to the next. Results are lost to the void, same as clojure.core/do, so side effects are expected. Returns a promise-chan which settles with the result of the last expression when the entire do! is done.
Note:
Asynchronous do. Execute expressions one after the other, awaiting the result of each one before moving on to the next. Results are lost to the void, same as clojure.core/do, so side effects are expected. Returns a promise-chan which settles with the result of the last expression when the entire do! is done. Note: * exprs can return a channel or something supported by IntoPromiseChan.
(adoseq bindings & body)Asynchronously consumes channel-like or collection-like sources for side effects, returning a promise-chan that settles to nil.
Binding forms follow Clojure doseq/for style for destructuring, nested bindings, :let, :when, and :while. Each element is consumed with await semantics. On :while short-circuit, errors, or cancellation, lifecycle-aware sources are returned/cleaned up; borrowed plain channels are only observed.
Asynchronously consumes channel-like or collection-like sources for side effects, returning a promise-chan that settles to nil. Binding forms follow Clojure doseq/for style for destructuring, nested bindings, :let, :when, and :while. Each element is consumed with await semantics. On :while short-circuit, errors, or cancellation, lifecycle-aware sources are returned/cleaned up; borrowed plain channels are only observed.
(afor bindings & body)Asynchronously comprehends over channel-like or collection-like sources, returning a promise-chan settled with an eager vector of body results.
Supports the same binding and qualifier forms as adoseq. Body-returned reduced values are ordinary values; use :while for short-circuiting.
Asynchronously comprehends over channel-like or collection-like sources, returning a promise-chan settled with an eager vector of body results. Supports the same binding and qualifier forms as adoseq. Body-returned reduced values are ordinary values; use :while for short-circuiting.
(ainto to source)(ainto to xf source)Asynchronously consumes source into to, returning a promise-chan settled with the completed collection.
With two arguments, behaves like async into. With three arguments, applies xf as a transducer. source may be channel-like or collection-like, and each element is consumed with await semantics.
Asynchronously consumes source into to, returning a promise-chan settled with the completed collection. With two arguments, behaves like async into. With three arguments, applies xf as a transducer. source may be channel-like or collection-like, and each element is consumed with await semantics.
(alet bindings & exprs)Asynchronous let. Binds result of async expressions to local binding, executing bindings in order one after the other.
Note:
Asynchronous let. Binds result of async expressions to local binding, executing bindings in order one after the other. Note: * exprs can return a channel or something supported by IntoPromiseChan.
(all chans)Takes a seqable of chans as an input, and returns a promise-chan that settles after all of the given chans have fulfilled in ok?, with a vector of the taken ok? results of the input chans. This returned promise-chan will settle when all of the input's chans have fulfilled, or if the input seqable contains no chans (only values or empty). It settles in error? immediately upon any of the input chans returning an error? or non-chans throwing an error?, and will contain the error? of the first taken chan to return one.
Note:
Takes a seqable of chans as an input, and returns a promise-chan that settles after all of the given chans have fulfilled in ok?, with a vector of the taken ok? results of the input chans. This returned promise-chan will settle when all of the input's chans have fulfilled, or if the input seqable contains no chans (only values or empty). It settles in error? immediately upon any of the input chans returning an error? or non-chans throwing an error?, and will contain the error? of the first taken chan to return one. Note: * chan can be a channel or something supported by IntoPromiseChan.
(all-settled chans)Takes a seqable of chans as an input, and returns a promise-chan that settles after all of the given chans have fulfilled in ok? or error?, with a vector of the taken ok? results and error? results of the input chans.
It is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each chan even when one errors.
In comparison, the promise-chan returned by all may be more appropriate if the tasks are dependent on each other / if you'd like to immediately stop upon any of them returning an error?.
Note:
Takes a seqable of chans as an input, and returns a promise-chan that settles after all of the given chans have fulfilled in ok? or error?, with a vector of the taken ok? results and error? results of the input chans. It is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each chan even when one errors. In comparison, the promise-chan returned by all may be more appropriate if the tasks are dependent on each other / if you'd like to immediately stop upon any of them returning an error?. Note: * chan can be a channel or something supported by IntoPromiseChan.
(anext source)Takes one raw value from channel-like source, returning a promise-chan.
If source is a cold async-style generator, taking starts it in the current scope. The returned promise-chan settles to the next value, or nil when the source is done. Errors are represented using normal async-style semantics: use wait/await to throw them, or wait*/await* to receive them as values.
anext observes borrowed plain channels without closing or cancelling them. Collection-like sources are not supported.
Takes one raw value from channel-like source, returning a promise-chan. If source is a cold async-style generator, taking starts it in the current scope. The returned promise-chan settles to the next value, or nil when the source is done. Errors are represented using normal async-style semantics: use wait/await to throw them, or wait*/await* to receive them as values. anext observes borrowed plain channels without closing or cancelling them. Collection-like sources are not supported.
(any chans)Returns a promise-chan that settles as soon as one of the chan in chans fulfills in ok?, with the value settled by that chan.
Unlike race, this will ignore chans that fulfilled with an error?. So if the first chan to fulfill does so with an error?, any will keep waiting for another chan to eventually fulfill in ok?.
If all chans fulfill in error?, returns an error containing the list of all the errors.
Note:
Returns a promise-chan that settles as soon as one of the chan in chans fulfills in ok?, with the value settled by that chan. Unlike race, this will ignore chans that fulfilled with an error?. So if the first chan to fulfill does so with an error?, any will keep waiting for another chan to eventually fulfill in ok?. If all chans fulfill in error?, returns an error containing the list of all the errors. Note: * chan can be a channel or something supported by IntoPromiseChan.
(areduce rf init source)Asynchronously reduces source with rf and init, returning a promise-chan settled with the final accumulator.
source may be channel-like or collection-like. Each element is consumed with await semantics, so Throwable values are thrown and values supported by IntoPromiseChan are awaited. If rf returns reduced, reduction stops early, lifecycle-aware sources are returned/cleaned up, and the promise-chan settles with the unwrapped reduced value.
rf runs on the async-pool and should be quick: do not block, park, wait, or perform heavy compute work inside it.
Asynchronously reduces source with rf and init, returning a promise-chan settled with the final accumulator. source may be channel-like or collection-like. Each element is consumed with await semantics, so Throwable values are thrown and values supported by IntoPromiseChan are awaited. If rf returns reduced, reduction stops early, lifecycle-aware sources are returned/cleaned up, and the promise-chan settles with the unwrapped reduced value. rf runs on the async-pool and should be quick: do not block, park, wait, or perform heavy compute work inside it.
(areturn source)Requests early cleanup for a lifecycle-aware async-style source.
Returns a promise-chan settling to nil after cleanup has completed. For borrowed plain channels, areturn is a no-op: it does not close or cancel the channel.
Requests early cleanup for a lifecycle-aware async-style source. Returns a promise-chan settling to nil after cleanup has completed. For borrowed plain channels, areturn is a no-op: it does not close or cancel the channel.
(async & body)Asynchronously execute body on the async-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown.
body will run on the async-pool, so if you plan on doing something blocking or compute heavy, use blocking or compute instead.
Asynchronously execute body on the async-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown. body will run on the async-pool, so if you plan on doing something blocking or compute heavy, use blocking or compute instead.
(async-generator & body)Creates a cold async-style channel whose body can yield many values.
The body runs on the async-pool when the returned channel is first consumed, not when the channel is created. Values published with yield are delivered as raw channel values, and channel close means the generator is done.
Accepts an optional options map. Currently supported:
Supports implicit trailing catch/finally forms like async, blocking, and compute.
Creates a cold async-style channel whose body can yield many values.
The body runs on the async-pool when the returned channel is first consumed,
not when the channel is created. Values published with yield are delivered as
raw channel values, and channel close means the generator is done.
Accepts an optional options map. Currently supported:
* :buffer-size - fixed, lossless output buffer size. Defaults to 0 for an
unbuffered, pull-based handoff.
Supports implicit trailing catch/finally forms like async, blocking, and
compute.(atransduce xf rf init source)Asynchronously transduces source with xf, rf, and init, returning a promise-chan settled with the completed reduction result.
source may be channel-like or collection-like. Early transducer completion, errors, and cancellation return/clean up lifecycle-aware sources. Transducer and reducing steps run on the async-pool and should be quick; do not block, park, wait, or perform heavy compute work inside them.
Asynchronously transduces source with xf, rf, and init, returning a promise-chan settled with the completed reduction result. source may be channel-like or collection-like. Early transducer completion, errors, and cancellation return/clean up lifecycle-aware sources. Transducer and reducing steps run on the async-pool and should be quick; do not block, park, wait, or perform heavy compute work inside them.
(await chan-or-value & body)Parking takes from chan-or-value so that any exception taken is re-thrown, returning the value settled by the producer.
Supports implicit-try to handle thrown exceptions such as:
(async (await (async (/ 1 0)) (catch ArithmeticException e (println e)) (catch Exception e (println "Other unexpected excpetion")) (finally (println "done"))))
Note:
Parking takes from chan-or-value so that any exception taken is re-thrown,
returning the value settled by the producer.
Supports implicit-try to handle thrown exceptions such as:
(async
(await (async (/ 1 0))
(catch ArithmeticException e
(println e))
(catch Exception e
(println "Other unexpected excpetion"))
(finally (println "done"))))
Note:
* chan can be a channel or something supported by IntoPromiseChan.(await* chan-or-value)Parking takes from chan-or-value so that any exception is returned, and with async-style promise values settled by their producers.
Note:
Parking takes from chan-or-value so that any exception is returned, and with async-style promise values settled by their producers. Note: * chan can be a channel or something supported by IntoPromiseChan.
(blocking & body)Asynchronously execute body on the blocking-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown.
body will run on the blocking-pool, so use this when you will be blocking or doing blocking io only.
Asynchronously execute body on the blocking-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown. body will run on the blocking-pool, so use this when you will be blocking or doing blocking io only.
(cancel! chan)(cancel! chan v)When called on chan, tries to tell processes currently executing over the chan that they should interrupt and short-circuit (aka cancel) their execution as soon as they can, as it is no longer needed.
The way cancellation is conveyed is by settling the return channel of async, blocking and compute blocks to a CancellationException, unless passed a v explicitly, in which case it will settle it with v.
When called on a lifecycle-aware async-style source, such as an async-generator, it requests lifecycle cleanup using the same path as areturn. This is fire-and-forget; use areturn when you need to wait for cleanup and finally blocks to finish.
That means by default a block that has its execution cancelled will return a CancellationException and thus awaiters and other takers of its result will see the exception and can handle it accordingly. If instead you want to cancel the block so it returns a value, pass in a v and the awaiters and takers will receive that value instead. You can't set nil as the cancelled value, attempting to do so will throw an IllegalArgumentException.
It is up to processes inside async, blocking and compute blocks to properly check for cancellation on a channel.
When called on chan, tries to tell processes currently executing over the chan that they should interrupt and short-circuit (aka cancel) their execution as soon as they can, as it is no longer needed. The way cancellation is conveyed is by settling the return channel of async, blocking and compute blocks to a CancellationException, unless passed a v explicitly, in which case it will settle it with v. When called on a lifecycle-aware async-style source, such as an async-generator, it requests lifecycle cleanup using the same path as areturn. This is fire-and-forget; use areturn when you need to wait for cleanup and finally blocks to finish. That means by default a block that has its execution cancelled will return a CancellationException and thus awaiters and other takers of its result will see the exception and can handle it accordingly. If instead you want to cancel the block so it returns a value, pass in a v and the awaiters and takers will receive that value instead. You can't set nil as the cancelled value, attempting to do so will throw an IllegalArgumentException. It is up to processes inside async, blocking and compute blocks to properly check for cancellation on a channel.
(cancelled?)Returns true if execution context was cancelled and thus should be interrupted/short-circuited, false otherwise.
Users are expected, when inside an execution block like async, blocking or compute, to check using (cancelled? or check-cancelled!) as often as they can in case someone tried to cancel their execution, in which case they should interrupt/short-circuit the work as soon as they can.
Returns true if execution context was cancelled and thus should be interrupted/short-circuited, false otherwise. Users are expected, when inside an execution block like async, blocking or compute, to check using (cancelled? or check-cancelled!) as often as they can in case someone tried to cancel their execution, in which case they should interrupt/short-circuit the work as soon as they can.
(catch chan error-handler)(catch chan pred-or-type error-handler)Parking takes the settled value from chan. If value is an error of pred-or-type, will call error-handler with it.
Returns a promise-chan settled with the value or the return of the error-handler.
error-handler will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
Parking takes the settled value from chan. If value is an error of pred-or-type, will call error-handler with it. Returns a promise-chan settled with the value or the return of the error-handler. error-handler will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(chain chan & fs)Chains multiple then together starting with chan like: (-> chan (then f1) (then f2) (then fs) ...)
fs will all run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
Chains multiple then together starting with chan like: (-> chan (then f1) (then f2) (then fs) ...) fs will all run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(check-cancelled!)Throws if execution context was cancelled and thus should be interrupted/short-circuited, returns nil.
Users are expected, when inside an execution block like async, blocking or compute, to check using (cancelled? or check-cancelled!) as often as they can in case someone tried to cancel their execution, in which case they should interrupt/short-circuit the work as soon as they can.
Throws if execution context was cancelled and thus should be interrupted/short-circuited, returns nil. Users are expected, when inside an execution block like async, blocking or compute, to check using (cancelled? or check-cancelled!) as often as they can in case someone tried to cancel their execution, in which case they should interrupt/short-circuit the work as soon as they can.
(clet bindings & body)Concurrent let. Executes all bound expressions in an async block so that the bindings run concurrently. If a later binding or the body depends on an earlier binding, that reference is automatically replaced with an await. In a blocking/compute context, await is transformed to wait for proper blocking behavior.
Notes:
Concurrent let. Executes all bound expressions in an async block so that
the bindings run concurrently. If a later binding or the body depends on an
earlier binding, that reference is automatically replaced with an await.
In a blocking/compute context, await is transformed to wait for proper
blocking behavior.
Notes:
* Bindings are evaluated in the async-pool; therefore, they should not
perform blocking I/O or heavy compute directly. If you need to do blocking
operations or heavy compute, wrap the binding in a blocking or compute call.
* This macro only supports simple symbol bindings; destructuring (vector or
map destructuring) is not supported.
* It will transform symbols even inside quoted forms, so literal code in quotes
may be rewritten unexpectedly.
* Inner local bindings (e.g. via a nested let) that shadow an outer binding are
not handled separately; the macro will attempt to rewrite every occurrence,
which may lead to incorrect replacements.
* Anonymous functions that use parameter names identical to outer bindings
will also be rewritten, which can cause unintended behavior if they are meant
to shadow those bindings.(compute & body)Asynchronously execute body on the compute-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown.
body will run on the compute-pool, so use this when you will be doing heavy computation, and don't block, if you're going to block use blocking instead. If you're doing a very small computation, like polling another chan, use async instead.
Asynchronously execute body on the compute-pool with support for cancellation, implicit-try, and returning a promise-chan settled with the result or any exception thrown. body will run on the compute-pool, so use this when you will be doing heavy computation, and don't block, if you're going to block use blocking instead. If you're doing a very small computation, like polling another chan, use async instead.
(defer ms value-or-fn)Waits ms time and then asynchronously executes value-or-fn, returning a promsie-chan settled with the result.
value-or-fn will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Waits ms time and then asynchronously executes value-or-fn, returning a promsie-chan settled with the result. value-or-fn will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
(detach & body)Runs body outside the current cancellation context.
Use when spawning work that should not be cancelled when the parent is cancelled or completed (fire-and-forget, background work, etc.):
(async (let [background (detach (async ...))] ; won't be cancelled with parent ...))
Can also be used around await*/wait* to prevent reading the parent's cancellation channel.
Runs body outside the current cancellation context.
Use when spawning work that should not be cancelled when the parent is
cancelled or completed (fire-and-forget, background work, etc.):
(async
(let [background (detach (async ...))] ; won't be cancelled with parent
...))
Can also be used around await*/wait* to prevent reading the parent's
cancellation channel.(error? v)Returns true if v is considered an error as per async-style's error representations, false otherwise. Valid error representations in async-style for now are:
Returns true if v is considered an error as per async-style's error representations, false otherwise. Valid error representations in async-style for now are: * instances of Throwable
(finally chan f)Parking takes the settled value from chan, and calls f with it no matter if the value is ok? or error?.
Returns a promise-chan settled with the taken value, and not the return of f, which means f is implied to be doing side-effect(s).
f will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
Parking takes the settled value from chan, and calls f with it no matter if the value is ok? or error?. Returns a promise-chan settled with the taken value, and not the return of f, which means f is implied to be doing side-effect(s). f will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(handle chan f)(handle chan ok-handler error-handler)Asynchronously executes f with the result of chan once available (f result), unlike then, handle will always execute f, when chan's result is an error f is called with the error (f error).
Returns a promise-chan settled with the result of f.
Alternatively, one can pass an ok-handler and an error-handler and the respective one will be called based on if chan's result is ok (ok-handler result) or an error (error-handler error).
f, ok-handler and error-handler will all run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
Asynchronously executes f with the result of chan once available (f result), unlike then, handle will always execute f, when chan's result is an error f is called with the error (f error). Returns a promise-chan settled with the result of f. Alternatively, one can pass an ok-handler and an error-handler and the respective one will be called based on if chan's result is ok (ok-handler result) or an error (error-handler error). f, ok-handler and error-handler will all run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(ok? v)Returns true if v is not considered an error as per async-style's error representations, false otherwise. Valid error representations in async-style for now are:
Returns true if v is not considered an error as per async-style's error representations, false otherwise. Valid error representations in async-style for now are: * instances of Throwable
(race chans)Returns a promise-chan that settles as soon as one of the chan in chans fulfill, with the value settled by that chan.
Unlike any, this will also return the first error? to be returned by one of the chans. So if the first chan to fulfill does so with an error?, race will return a promise-chan settled with that error.
Note:
Returns a promise-chan that settles as soon as one of the chan in chans fulfill, with the value settled by that chan. Unlike any, this will also return the first error? to be returned by one of the chans. So if the first chan to fulfill does so with an error?, race will return a promise-chan settled with that error. Note: * chan can be a channel or something supported by IntoPromiseChan.
(sleep ms)Asynchronously sleep ms time, returns a promise-chan which settles after ms time.
Asynchronously sleep ms time, returns a promise-chan which settles after ms time.
(then chan f)Asynchronously executes f with the result of chan once available, unless chan results in an error, in which case f is not executed.
Returns a promise-chan settled with the result of f or the error.
f will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
Asynchronously executes f with the result of chan once available, unless chan results in an error, in which case f is not executed. Returns a promise-chan settled with the result of f or the error. f will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(time expr)(time expr print-fn)Evaluates expr and prints the time it took. Returns the value of expr. If expr evaluates to a channel, it waits for channel to fulfill before printing the time it took.
Note:
Evaluates expr and prints the time it took. Returns the value of expr. If expr evaluates to a channel, it waits for channel to fulfill before printing the time it took. Note: * expr can return a channel or something supported by IntoPromiseChan.
(timeout chan ms)(timeout chan ms timed-out-value-or-fn)If chan fulfills before ms time has passed, return a promise-chan settled with the result, else returns a promise-chan settled with a TimeoutException or the result of timed-out-value-or-fn.
timed-out-value-or-fn will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively.
Note:
If chan fulfills before ms time has passed, return a promise-chan settled with the result, else returns a promise-chan settled with a TimeoutException or the result of timed-out-value-or-fn. timed-out-value-or-fn will run on the async-pool, so if you plan on doing something blocking or compute heavy, remember to wrap it in a blocking or compute respectively. Note: * chan can be a channel or something supported by IntoPromiseChan.
(wait chan-or-value & body)Blocking takes from chan-or-value so that any exception taken is re-thrown, returning the value settled by the producer.
Supports implicit-try to handle thrown exceptions such as:
(wait (async (/ 1 0)) (catch ArithmeticException e (println e)) (catch Exception e (println "Other unexpected excpetion")) (finally (println "done")))
Note:
Blocking takes from chan-or-value so that any exception taken is re-thrown,
returning the value settled by the producer.
Supports implicit-try to handle thrown exceptions such as:
(wait (async (/ 1 0))
(catch ArithmeticException e
(println e))
(catch Exception e
(println "Other unexpected excpetion"))
(finally (println "done")))
Note:
* chan can be a channel or something supported by IntoPromiseChan.(wait* chan-or-value)Blocking takes from chan-or-value so that any exception is returned, and with async-style promise values settled by their producers.
Note:
Blocking takes from chan-or-value so that any exception is returned, and with async-style promise values settled by their producers. Note: * chan can be a channel or something supported by IntoPromiseChan.
(yield v)Publishes one value from inside async-generator.
The value is consumed through await before it is put on the output channel, so yielding a promise-chan, Future, or CompletableFuture exposes its settled value to downstream consumers. yield parks when the configured generator buffer is full and returns nil on success.
async-generator cannot yield nil, because nil is core.async's closed-channel value and means the source is done.
Publishes one value from inside async-generator. The value is consumed through await before it is put on the output channel, so yielding a promise-chan, Future, or CompletableFuture exposes its settled value to downstream consumers. yield parks when the configured generator buffer is full and returns nil on success. async-generator cannot yield nil, because nil is core.async's closed-channel value and means the source is done.
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 |