async/await syntax for functions that take a successful- and an exceptional callback in the last two arguments, a pattern known as continuation-passing style (CPS) and popularised by Ring and clj-http.
async/await syntax for functions that take a successful- and an exceptional callback in the last two arguments, a pattern known as continuation-passing style (CPS) and popularised by Ring and clj-http.
(afn name? [params*] body)
Defines an asynchronous function. Declared arguments are extended with two continuation arguments of &resolve and &raise and these continuations will be called with the function result or any exception thrown respectively.
Executes in the calling thread up until the first await clause. Execution is then resumed in the thread the awaited function invokes its continuation in. This may still be the calling thread.
JVM monitor operations (monitor-enter, monitor-exit and locking macro) are not supported in the body and their use will lead to concurrency bugs. Currently there is no warning when this is the case.
Only one arity is allowed.
Defines an asynchronous function. Declared arguments are extended with two continuation arguments of &resolve and &raise and these continuations will be called with the function result or any exception thrown respectively. Executes in the calling thread up until the first await clause. Execution is then resumed in the thread the awaited function invokes its continuation in. This may still be the calling thread. JVM monitor operations (monitor-enter, monitor-exit and locking macro) are not supported in the body and their use will lead to concurrency bugs. Currently there is no warning when this is the case. Only one arity is allowed.
(async resolve raise & body)
Deprecated - use ((afn [] body*) resolve raise).
Deprecated - use ((afn [] body*) resolve raise).
(await cps-fn & args)
Awaits the asynchronous execution of continuation-passing style function cps-fn, applying it to args and two extra callback functions: resolve and raise. cps-fn is expected to eventually either call resolve with the result, call raise with the exception or just throw in the calling thread. The return value of cps-fn is ignored. Effectively returns the value passed to resolve or throws the exception passed to raise (or thrown) but does not block the calling tread.
Must be called in an asynchronous function. Note that any nested functions defined with fn, letfn, reify or deftype are considered outside of asynchronous scope.
Awaits the asynchronous execution of continuation-passing style function cps-fn, applying it to args and two extra callback functions: resolve and raise. cps-fn is expected to eventually either call resolve with the result, call raise with the exception or just throw in the calling thread. The return value of cps-fn is ignored. Effectively returns the value passed to resolve or throws the exception passed to raise (or thrown) but does not block the calling tread. Must be called in an asynchronous function. Note that any nested functions defined with fn, letfn, reify or deftype are considered outside of asynchronous scope.
(await! cps-fn & args)
Like await but blocks the calling thread. Do not use inside an asynchronous function.
Like await but blocks the calling thread. Do not use inside an asynchronous function.
(blocking & body)
Returns a CPS function that will execute the body in a future block and trigger its continuation within that future. Use to avoid long-running IO from blocking the caller's thread. Use: (await (blocking (slurp "a-very-long-file.txt")))
Returns a CPS function that will execute the body in a future block and trigger its continuation within that future. Use to avoid long-running IO from blocking the caller's thread. Use: (await (blocking (slurp "a-very-long-file.txt")))
(defn-async name doc-string? attr-map? [params*] body)
Like defn, but the function defined is asynchronous (see afn).
Like defn, but the function defined is asynchronous (see afn).
Deprecated - renamed to afn.
Deprecated - renamed to afn.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close