co.paralleluniverse.pulsar.async documentation
Implementation of core.async
<!!
takes a val from port. Will return nil if closed. Will block
if nothing is available.
Pulsar implementation: Identical to <!. May be used outside go blocks as well.
>!!
puts a val into port. nil values are not allowed. Will block if no
buffer space is available. Returns nil.
Pulsar implementation: Identical to <!!. May be used outside go blocks as well.
alt!
macro
(alt! & clauses)
Makes a single choice between one of several channel operations,
as if by alts!, returning the value of the result expr corresponding
to the operation completed. Must be called inside a (go ...) block.
Each clause takes the form of:
channel-op[s] result-expr
where channel-ops is one of:
take-port - a single port to take
[take-port | [put-port put-val] ...] - a vector of ports as per alts!
:default | :priority - an option for alts!
and result-expr is either a list beginning with a vector, whereupon that
vector will be treated as a binding for the [val port] return of the
operation, else any other expression.
(alt!
[c t] ([val ch] (foo ch val))
x ([v] v)
[[out val]] :wrote
:default 42)
Each option may appear at most once. The choice and parking
characteristics are those of alts!.
alt!!
macro
(alt!! & args)
Like alt!, except as if by alts!!, will block until completed, and
not intended for use in (go ...) blocks.
Pulsar implementation: identical to alt! and may be
used in go blocks
alts!
(alts! ports & {:as opts})
Completes at most one of several channel operations. Must be called
inside a (go ...) block. ports is a set of channel endpoints, which
can be either a channel to take from or a vector of
[channel-to-put-to val-to-put], in any combination. Takes will be
made as if by <!, and puts will be made as if by >!. Unless
the :priority option is true, if more than one port operation is
ready a non-deterministic choice will be made. If no operation is
ready and a :default value is supplied, [default-val :default] will
be returned, otherwise alts! will park until the first operation to
become ready completes. Returns [val port] of the completed
operation, where val is the value taken for takes, and nil for puts.
opts are passed as :key val ... Supported options:
:default val - the value to use if none of the operations are immediately ready
:priority true - (default nil) when true, the operations will be tried in order.
Note: there is no guarantee that the port exps or val exprs will be
used, nor in what order should they be, so they should not be
depended upon for side effects.
alts!!
macro
(alts!! & args)
Like alts!, except takes will be made as if by <!!, and puts will
be made as if by >!!, will block until completed, and not intended
for use in (go ...) blocks.
Pulsar implementation: identical to alt! and may be
used in go blocks
buffer
(buffer n)
Returns a fixed buffer of size n. When full, puts will block/park.
chan
(chan)
(chan buf-or-n)
Creates a channel with an optional buffer. If buf-or-n is a number,
will create and use a fixed buffer of that size.
close!
(close! chan)
Closes a channel. The channel will no longer accept any puts (they
will be ignored). Data in the channel remains available for taking, until
exhausted, after which takes will return nil. If there are any
pending takes, they will be dispatched with nil. Closing a closed
channel is a no-op. Returns nil.
dropping-buffer
(dropping-buffer n)
Returns a buffer of size n. When full, puts will complete but
val will be dropped (no transfer).
go
macro
(go & body)
Asynchronously executes the body, returning immediately to the
calling thread. Additionally, any visible calls to <!, >! and alt!/alts!
channel operations within the body will block (if necessary) by
'parking' the calling thread rather than tying up an OS thread (or
the only JS thread when in ClojureScript). Upon completion of the
operation, the body will be resumed.
Returns a channel which will receive the result of the body when
completed
put!
(put! port val)
(put! port val fn0)
(put! port val fn0 on-caller?)
Asynchronously puts a val into port, calling fn0 (if supplied) when
complete. nil values are not allowed. Will throw if closed. If
on-caller? (default true) is true, and the put is immediately
accepted, will call fn0 on calling thread. Returns nil.
sliding-buffer
(sliding-buffer n)
Returns a buffer of size n. When full, puts will complete, and be
buffered, but oldest elements in buffer will be dropped (not
transferred).
take!
(take! port fn1)
(take! port fn1 on-caller?)
Asynchronously takes a val from port, passing to fn1. Will pass nil
if closed. If on-caller? (default true) is true, and value is
immediately available, will call fn1 on calling thread.
Returns nil.
thread
macro
(thread & body)
Executes the body in another thread, returning immediately to the
calling thread. Returns a channel which will receive the result of
the body when completed.
thread-call
(thread-call f)
Executes f in another thread, returning immediately to the calling
thread. Returns a channel which will receive the result of calling
f when completed.
timeout
(timeout msecs)
Returns a channel that will close after msecs