Implementation of the interceptor pattern based on an asynchronous promise chain.
Interceptors map hook functions to the three execution stages :enter
,
:leave
, and :error
. All hook functions are optional, will be passed
the current execution context, and need to return an updated context.
When executing a context, first each :enter
hook is triggered in order.
After that, each intereptor's :leave
hook will be invoked in reverse order.
At any point, when an error occurs the execution of remaining interceptors is
terminated and the :error
function of previously processed interceptors is
triggered in reverse order.
The ::queue
of pending interceptors and ::stack
of partially processed
inteceptors are always present on the context. It is perfectly valid for
interceptor hooks to alter those in order to change execution.
The current error is available via ::error
. To catch an error return a
context with the key removed. To signal an error return a context with the
::error
key present.
Implementation of the interceptor pattern based on an asynchronous promise chain. Interceptors map hook functions to the three execution stages `:enter`, `:leave`, and `:error`. All hook functions are optional, will be passed the current execution context, and need to return an updated context. When executing a context, first each `:enter` hook is triggered in order. After that, each intereptor's `:leave` hook will be invoked in reverse order. At any point, when an error occurs the execution of remaining interceptors is terminated and the `:error` function of previously processed interceptors is triggered in reverse order. The `::queue` of pending interceptors and `::stack` of partially processed inteceptors are always present on the context. It is perfectly valid for interceptor hooks to alter those in order to change execution. The current error is available via `::error`. To catch an error return a context with the key removed. To signal an error return a context with the `::error` key present.
(done? ctx n)
Returns true, if there are no more pending execution steps.
Returns true, if there are no more pending execution steps.
(enqueue ctx n txs)
Add interceptors to the end of the execution queue.
Add interceptors to the end of the execution queue.
(enter-1 ctx n)
Execute next enter step.
Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
Execute next enter step. Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
(error? ctx n)
Returns true, if execution is in error stage.
Returns true, if execution is in error stage.
(execute ctx n txs)
Apply a chain of interceptors txs
to context ctx
.
ctx
can be a plain map and will be elevated to be an executable context by
enqueueing txs
. Returns a promise resolving to the updated context.
Apply a chain of interceptors `txs` to context `ctx`. `ctx` can be a plain map and will be elevated to be an executable context by enqueueing `txs`. Returns a promise resolving to the updated context.
(execute-1 ctx n)
Execute next enter, leave, or error step.
Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
Execute next enter, leave, or error step. Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
(execute-all ctx n)
Execute all enter, leave, or error steps.
Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
Execute all enter, leave, or error steps. Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
(leave-1 ctx n)
Execute next leave or error step.
Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
Execute next leave or error step. Returns a promise resolving to the updated context. Fails gracefully, if not applicable.
(stack ctx n txs)
Add inteceptors to the top of the execution stack.
Add inteceptors to the top of the execution stack.
(terminate ctx n)
Drop execution of any pending interceptors and immediately switch to the leave stage.
Drop execution of any pending interceptors and immediately switch to the leave stage.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close