Skip to content

clojure.core.async/pub

View this page on ClojureDocs

Type: function Added: Clojure unknown Examples: 5 Runnable: 0
([ch topic-fn] [ch topic-fn buf-fn])

Creates and returns a pub(lication) of the supplied channel, partitioned into topics by the topic-fn. topic-fn will be applied to each value on the channel and the result will determine the 'topic' on which that value will be put. Channels can be subscribed to receive copies of topics using 'sub', and unsubscribed using 'unsub'. Each topic will be handled by an internal mult on a dedicated channel. By default these internal channels are unbuffered, but a buf-fn can be supplied which, given a topic, creates a buffer with desired properties.

Each item is distributed to all subs in parallel and synchronously, i.e. each sub must accept before the next item is distributed. Use buffering/windowing to prevent slow subs from holding up the pub.

Items received when there are no matching subs get dropped.

Note that if buf-fns are used then each topic is handled asynchronously, i.e. if a channel is subscribed to more than one topic it should not expect them to be interleaved identically with the source.

Examples

by runexec on . May have evaluation errors.
by freckletonj on . May have evaluation errors.
by milelo on . May have evaluation errors.
by jdf-id-au on . May have evaluation errors.
by CalebMacdonaldBlack on . May have evaluation errors.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.