Liking cljdoc? Tell your friends :D

tservice-core.tasks.async

Provides a very simply event bus using core.async to allow publishing and subscribing to interesting topics happening throughout the tservice system in a decoupled way. It's based on metabase.events.

Regarding Events Initialization:

Internal Events: The most appropriate way to initialize event listeners in any tservice.events.* namespace (you can use setup-custom-namespace to change it) is to implement the events-init function which accepts zero arguments. This function is dynamically resolved and called exactly once when the application goes through normal startup procedures. Inside this function you can do any work needed and add your events subscribers to the bus as usual via start-event-listener!.

Examples:

; Call these code in app entrypoint.
;; First Step
(setup-custom-namespace "tservice" :sub-ns "events")

;; Second Step (Call it when the app instance is launched.)
(initialize-events!)

; Defined in each event.
;; Define event handler
(defn- test-handler! 
   [{:keys [test-content]}]
   (println test-content))

;; Define events-init function.
(def events-init
  "Automatically called during startup; start event listener for test event."
  (make-events-init "test" test-handler!))

; When you need to trigger an event, call this code 
(publish-event! "test" {:test-content "This is a test."})

External Events: If you use the event bus in plugin, you need to use make-events-init to generate event initializer and initialize the event in plugin configuration file. When the above setting is successful, you can use publish-event! to trigger an event.

Provides a very simply event bus using `core.async` to allow publishing and subscribing to interesting topics
happening throughout the tservice system in a decoupled way. It's based on `metabase.events`.

## Regarding Events Initialization:

Internal Events: The most appropriate way to initialize event listeners in any `tservice.events.*` namespace 
(you can use [[setup-custom-namespace]] to change it) is to implement the
`events-init` function which accepts zero arguments. This function is dynamically resolved and called exactly once
when the application goes through normal startup procedures. Inside this function you can do any work needed and add
your events subscribers to the bus as usual via `start-event-listener!`.

Examples:

```clojure
; Call these code in app entrypoint.
;; First Step
(setup-custom-namespace "tservice" :sub-ns "events")

;; Second Step (Call it when the app instance is launched.)
(initialize-events!)

; Defined in each event.
;; Define event handler
(defn- test-handler! 
   [{:keys [test-content]}]
   (println test-content))

;; Define events-init function.
(def events-init
  "Automatically called during startup; start event listener for test event."
  (make-events-init "test" test-handler!))

; When you need to trigger an event, call this code 
(publish-event! "test" {:test-content "This is a test."})
```

External Events: If you use the event bus in plugin, you need to use [[make-events-init]] to 
generate event initializer and initialize the event in plugin configuration file.
When the above setting is successful, you can use publish-event! to trigger an event.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close