promesa.exec
Executors & Schedulers facilities.
cached-executor
(cached-executor & {:keys [max-size factory keepalive], :or {keepalive 60000, max-size Integer/MAX_VALUE}})A cached thread executor pool constructor.
current-thread-executor
(current-thread-executor)Creates an executor instance that run tasks in the same thread.
default-current-thread-executor
Default Executor instance that runs the task in the same thread.
default-executor
Default executor instance, ForkJoinPool/commonPool in JVM, MicrotaskExecutor on JS.
exec!
(exec! f)(exec! executor f)Run the task in the provided executor, returns nil. Analogous to the (.execute executor f). Fire and forget.
executor?
(executor? o)Returns true if o is an instane of Executor or satisfies IExecutor protocol.
fixed-executor
(fixed-executor & {:keys [parallelism factory]})A fixed thread executor pool constructor.
fn->thread
(fn->thread f & {:keys [daemon start priority name], :or {daemon true, start true, priority Thread/NORM_PRIORITY}})forkjoin-executor
(forkjoin-executor & {:keys [factory async parallelism keepalive core-size max-size], :or {max-size 32767, async true, keepalive 60000}})forkjoin-thread-factory
(forkjoin-thread-factory & {:keys [name daemon], :or {name "promesa/forkjoin/%s", daemon true}})interrupted?
(interrupted?)(interrupted? thread)Check if the thread has the interrupted flag set.
There are two special cases:
Using the :current keyword as argument will check the interrupted flag on the current thread.
Using the arity 0 (passing no arguments), then the current thread will be checked and WARNING the interrupted flag reset to false.
pmap
(pmap f coll)(pmap f coll & colls)Analogous to the clojure.core/pmap with the excetion that it allows use a custom executor (binded to default-executor var) The default clojure chunk size (32) is used for evaluation and the real parallelism is determined by the provided executor.
EXPERIMENTAL API: This function should be considered EXPERIMENTAL and may be changed or removed in future versions until this notification is removed.
schedule!
(schedule! ms f)(schedule! scheduler ms f)Schedule a callable to be executed after the ms delay is reached.
In JVM it uses a scheduled executor service and in JS it uses the setTimeout function.
scheduled-executor
(scheduled-executor & {:keys [parallelism factory], :or {parallelism 1}})A scheduled thread pool constructor. A ScheduledExecutor (IScheduler in CLJS) instance allows execute asynchronous tasks some time later.
single-executor
(single-executor & {:keys [factory]})A single thread executor pool constructor.
sleep
(sleep ms)Turn the current thread to sleep accept a number of milliseconds or Duration instance.
submit!
(submit! f)(submit! executor f)Submit a task to be executed in a provided executor and return a promise that will be completed with the return value of a task.
A task is a plain clojure function.
thread
macro
(thread opts & body)A low-level, not-pooled thread constructor, it accepts an optional map as first argument and the body. The options map is interepreted as options if a literal map is provided. The available options are: :name, :priority, :daemon and :virtual. The :virtual option is ignored if you are using a JVM that has no support for Virtual Threads.
thread-call
(thread-call f & {:as opts})Advanced version of p/thread-call that creates and starts a thread configured with opts. No executor service is used, this will start a plain unpooled thread.
thread-factory
(thread-factory & {:keys [name daemon priority], :or {daemon true, priority Thread/NORM_PRIORITY, name "promesa/thread/%s"}})Returns an instance of promesa default thread factory.
throw-uncaught!
(throw-uncaught! cause)Throw an exception to the current uncaught exception handler.
with-dispatch
macro
(with-dispatch executor & body)Helper macro for dispatch execution of the body to an executor service. The returned promise is not cancellable (the body will be executed independently of the cancellation).
with-dispatch!
macro
(with-dispatch! executor & body)Blocking version of with-dispatch. Useful when you want to dispatch a blocking operation to a separated thread and join current thread waiting for result; effective when current thread is virtual thread.
with-executor
macro
(with-executor executor & body)Binds the default-executor var with the provided executor, executes the macro body. It also can optionally shutdown or shutdown and interrupt on termination if you provide ^:shutdown and ^:interrupt metadata.
EXPERIMENTAL API: This function should be considered EXPERIMENTAL and may be changed or removed in future versions until this notification is removed.
work-stealing-executor
(work-stealing-executor & params)An alias for the forkjoin-executor.