Liking cljdoc? Tell your friends :D

peripheral.core


attachclj

(attach component k attach-component)
(attach component k attach-component dependencies)

Attach the given component to this one (associng it using k and having it depend on dependencies).

Attach the given component to this one (associng it using `k` and having it depend on `dependencies`).
sourceraw docstring

concurrentlyclj

(concurrently component-seq)

Tag the seq of components as elligible to be concurrently started. The return value is the same sequence of components, but #'start-all will start them concurrently.

Tag the seq of components as elligible to be concurrently started.
The return value is the same sequence of components, but #'start-all
will start them concurrently.
sourceraw docstring

connectcljdeprecated

(connect m src-id dst-id)
(connect m src-id src-key dst-id)

Let the component identified by src-id be using the component identified by dst-id as a dependency to be assoc'd in at the key src-key.

Let the component identified by `src-id` be using the component identified
by `dst-id` as a dependency to be assoc'd in at the key `src-key`.
sourceraw docstring

defcomponentcljmacro

(defcomponent id dependencies & component-logic)

Create new component type from a vector of dependencies (the components/fields that should be filled before the component is started, as well as a series of keyword/start/stop forms.

Each keyword has to be followed by a form that will be executed at startup and optionally a (non-keyword) function to be run at shutdown.

(defcomponent LoopRunner [f interval]
  :data   (fetch-some-data!)
  :thread (doto (Thread. #(while (not (.isInterrupted ...)) ...))
            (.start))
          #(.interrupt ^Thread %))

The results of the form/function will be assoc'd into the component. Please use the map->... function to create an instance of the record. Using fields with the namespace peripheral you can manipulate the component record directly:

(defcomponent TestComponent [...]
  :peripheral/start   #(...)      ;; called before fields are initialized
  :peripheral/started #(...)      ;; called after fields are initialized
  :peripheral/stop    #(...)      ;; called before fields are cleaned up
  :peripheral/stopped #(...))     ;; called after fields are cleaned up

Note that these take a function, not a form, and only allow for one value!

If you don't need to alter the component record, the 'on' prefix can be used to directly execute forms:

(defcomponent TestComponent [...]
  :on/start (println "starting"))

Finally, if you need access to the whole component, you can bind it to a symbol using ':this/as':

(defcomponent TestComponent [x]
  :this/as *this*
  :y (+ (:x *this*) 10)
  :z (- (:y *this*) 5))
Create new component type from a vector of `dependencies` (the components/fields that should
be filled before the component is started, as well as a series of keyword/start/stop forms.

Each keyword has to be followed by a form that will be executed at startup and optionally a
(non-keyword) function to be run at shutdown.

```
(defcomponent LoopRunner [f interval]
  :data   (fetch-some-data!)
  :thread (doto (Thread. #(while (not (.isInterrupted ...)) ...))
            (.start))
          #(.interrupt ^Thread %))
```

The results of the form/function will be assoc'd into the component. Please use the `map->...`
function to create an instance of the record. Using fields with the namespace `peripheral` you
can manipulate the component record directly:

```
(defcomponent TestComponent [...]
  :peripheral/start   #(...)      ;; called before fields are initialized
  :peripheral/started #(...)      ;; called after fields are initialized
  :peripheral/stop    #(...)      ;; called before fields are cleaned up
  :peripheral/stopped #(...))     ;; called after fields are cleaned up
```

Note that these take a function, not a form, and only allow for one value!

If you don't need to alter the component record, the 'on' prefix can be used to directly
execute forms:

```
(defcomponent TestComponent [...]
  :on/start (println "starting"))
```

Finally, if you need access to the whole component, you can bind it to a symbol using
':this/as':

```
(defcomponent TestComponent [x]
  :this/as *this*
  :y (+ (:x *this*) 10)
  :z (- (:y *this*) 5))
```
sourceraw docstring

defsystemcljmacrodeprecated

(defsystem id components & logic)
source

defsystem+cljmacro

(defsystem+ id & components)
(defsystem+ id [dependency ...] & components)

Create a new system of components. Example:

(defsystem+ MySystem [^:global configuration, api-options]
  :engine    []
  :monitor   [:scheduler :api]
  :api       [:engine {:options :api-options}]
  :scheduler [:engine])

On startup, the following injections will happen:

  • :configuration into :engine, :api and :scheduler (since it is marked as :global),
  • :engine into :api and :scheduler,
  • :api-options - aliased as :options - into :api,
  • :scheduler and :api into :monitor.

It is possible to give default values for each component using the :default metadata:

(defsystem+ MySystem [...]
  :engine ^{:default (default-engine)} []
  ...)

Unless the key :engine is present and non-nil on system startup, it'll be filled with the result of (default-engine).

Create a new system of components. Example:

    (defsystem+ MySystem [^:global configuration, api-options]
      :engine    []
      :monitor   [:scheduler :api]
      :api       [:engine {:options :api-options}]
      :scheduler [:engine])

On startup, the following injections will happen:

- `:configuration` into `:engine`, `:api` and `:scheduler` (since it is
  marked as `:global`),
- `:engine` into `:api` and `:scheduler`,
- `:api-options` - aliased as `:options` - into `:api`,
- `:scheduler` and `:api` into `:monitor`.

It is possible to give default values for each component using the `:default`
metadata:

    (defsystem+ MySystem [...]
      :engine ^{:default (default-engine)} []
      ...)

Unless the key `:engine` is present and non-nil on system startup, it'll
be filled with the result of `(default-engine)`.
sourceraw docstring

detachclj

(detach component k)

Detach the given component key from this component.

Detach the given component key from this component.
sourceraw docstring

reify-componentcljmacro

(reify-component & component-logic)
(reify-component dependencies & component-logic)

Create a one-off component (i.e. without creating an explicit component record). The syntax is identical to defcomponent without the class name.

(let [db-config {...}]
  (reify-component
    :db (connect! db-config) disconnect!
    ...))

The resulting value will implement all map interfaces, as well as the com.stuartsierra.component/Lifecycle protocol.

Create a one-off component (i.e. without creating an explicit component
record). The syntax is identical to [[defcomponent]] without the class name.

```
(let [db-config {...}]
  (reify-component
    :db (connect! db-config) disconnect!
    ...))
```

The resulting value will implement all map interfaces, as well as the
`com.stuartsierra.component/Lifecycle` protocol.
sourceraw docstring

restartclj

(restart component)

Restart the given component by calling stop and start.

Restart the given component by calling `stop` and `start`.
sourceraw docstring

running?clj

(running? component)

Check whether the component is running (per its metadata).

Check whether the component is running (per its metadata).
sourceraw docstring

startclj

(start component)

Begins operation of this component. Synchronous, does not return until the component is started. Returns an updated version of this component.

Begins operation of this component. Synchronous, does not return
until the component is started. Returns an updated version of this
component.
sourceraw docstring

stopclj

(stop component)

Ceases operation of this component. Synchronous, does not return until the component is stopped. Returns an updated version of this component.

Ceases operation of this component. Synchronous, does not return
until the component is stopped. Returns an updated version of this
component.
sourceraw docstring

subsystemclj

(subsystem system components)

Create subsystem. The resulting system will only start the given components and their dependencies.

Create subsystem. The resulting system will only start the given
components and their dependencies.
sourceraw docstring

with-startcljmacro

(with-start [form component & more] & body)

Start the given component, binding the started component to the given form, ensuring the shutdown of the component after the body has been executed.

Start the given component, binding the started component to the given form,
ensuring the shutdown of the component after the body has been executed.
sourceraw docstring

with-start*clj

(with-start* component f)

Start the given component, call the given function with the started component as only parameter, then stop the component.

Start the given component, call the given function with the started component
as only parameter, then stop the component.
sourceraw docstring

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

× close