Liking cljdoc? Tell your friends :D

rockbox.events

Event registry and dispatch.

Listeners are stored on the client itself (in an atom) so a single client value can be passed around and shared between threads safely.

Pipe-friendly callback API

(-> client
    (rb/connect)
    (events/on :track-changed (fn [t] (println "▶" (:title t))))
    (events/on :status-changed (fn [s] (println "status:" s))))

core.async channel API

(require '[clojure.core.async :as a])
(def ch (events/channel client :track-changed))
(a/go-loop []
  (when-let [t (a/<! ch)]
    (println (:title t))
    (recur)))

Supported events: :track-changed :status-changed :playlist-changed :ws-open :ws-close :ws-error

Event registry and dispatch.

Listeners are stored on the client itself (in an atom) so a single client
value can be passed around and shared between threads safely.

## Pipe-friendly callback API

    (-> client
        (rb/connect)
        (events/on :track-changed (fn [t] (println "▶" (:title t))))
        (events/on :status-changed (fn [s] (println "status:" s))))

## core.async channel API

    (require '[clojure.core.async :as a])
    (def ch (events/channel client :track-changed))
    (a/go-loop []
      (when-let [t (a/<! ch)]
        (println (:title t))
        (recur)))

Supported events: `:track-changed :status-changed :playlist-changed
                  :ws-open :ws-close :ws-error`
raw docstring

channelclj

(channel client event)
(channel client event {:keys [buf] :or {buf 16}})

Return a core.async channel that receives every payload for event. The returned channel is closed when its underlying listener is removed via close-channel!. Buffer defaults to 16; pass {:buf n} (or a buffer) to override.

(def ch (events/channel client :track-changed))
(a/go-loop []
  (when-let [t (a/<! ch)]
    (println (:title t))
    (recur)))
Return a `core.async` channel that receives every payload for `event`.
The returned channel is closed when its underlying listener is removed via
`close-channel!`. Buffer defaults to 16; pass `{:buf n}` (or a buffer) to
override.

    (def ch (events/channel client :track-changed))
    (a/go-loop []
      (when-let [t (a/<! ch)]
        (println (:title t))
        (recur)))
sourceraw docstring

close-channel!clj

(close-channel! client ch)

Close a channel returned by channel and unregister its underlying listener.

Close a channel returned by `channel` and unregister its underlying listener.
sourceraw docstring

emitclj

(emit client event payload)

Internal — call every listener for event. Used by the WS layer.

Internal — call every listener for `event`. Used by the WS layer.
sourceraw docstring

event-keysclj

source

offclj

(off client event listener)

Remove a listener. Returns the client.

Remove a listener. Returns the client.
sourceraw docstring

off-allclj

(off-all client)
(off-all client event)

Remove every listener (or every listener for a single event).

Remove every listener (or every listener for a single event).
sourceraw docstring

onclj

(on client event listener)

Register a listener for an event. Returns the client (so the call composes with ->). The listener receives one argument — the event payload (or nil for events with no payload, like :ws-open).

Register a listener for an event. Returns the client (so the call composes
with `->`). The listener receives one argument — the event payload (or `nil`
for events with no payload, like `:ws-open`).
sourceraw docstring

onceclj

(once client event listener)

Register a one-shot listener. Returns the client.

Register a one-shot listener. Returns the client.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close