Liking cljdoc? Tell your friends :D

fx.layer

Composable dependency injection and resource lifecycle management inspired by Effect-ts and ZIO.

Layers model recipes for acquiring and releasing environmental context and services. Layers can be composed horizontally with merge>, vertically with compose>, and provided to effect pipelines with provide-layer> or managed with start-layer! and launch-sync!.

Composable dependency injection and resource lifecycle management inspired by Effect-ts and ZIO.

Layers model recipes for acquiring and releasing environmental context and services.
Layers can be composed horizontally with `merge>`, vertically with `compose>`,
and provided to effect pipelines with `provide-layer>` or managed with `start-layer!`
and `launch-sync!`.
raw docstring

->LayerSystemclj/s

(->LayerSystem context scope)

Constructs a LayerSystem instance.

Constructs a `LayerSystem` instance.
raw docstring

compose>clj/s

(compose>)
(compose> layer)
(compose> l1 l2)
(compose> l1 l2 & more)

Composes layers vertically. Each layer in the sequence is provided with the accumulated context of all previous layers. Resources are released in reverse acquisition order.

Composes layers vertically. Each layer in the sequence is provided with the accumulated
context of all previous layers. Resources are released in reverse acquisition order.
raw docstring

from-effect>clj/s

(from-effect> key effect)

Creates a layer providing {key val} by evaluating effect without release lifecycle.

Creates a layer providing `{key val}` by evaluating `effect` without release lifecycle.
raw docstring

from-value>clj/s

(from-value> key val)

Creates a layer providing {key val} with no lifecycle management.

Creates a layer providing `{key val}` with no lifecycle management.
raw docstring

from-values>clj/s

(from-values> context-map)

Creates a layer providing context-map with no lifecycle management.

Creates a layer providing `context-map` with no lifecycle management.
raw docstring

ILayerclj/sprotocol

Protocol for composable dependency injection and lifecycle management layers.

Protocol for composable dependency injection and lifecycle management layers.

-build-effclj/s

(-build-eff this scope)

Returns an IEffect that builds the layer within scope and yields the context map.

Returns an `IEffect` that builds the layer within `scope` and yields the context map.
raw docstring

IScopeclj/sprotocol

Protocol for managing resource finalizers within a lifecycle scope.

Protocol for managing resource finalizers within a lifecycle scope.

add-finalizer!clj/s

(add-finalizer! this finalizer-eff)

Registers a finalizer effect into the scope.

Registers a finalizer effect into the scope.

close-scope!>clj/s

(close-scope!> this)

Returns an effect that deterministically executes all registered finalizers in reverse order of registration.

Returns an effect that deterministically executes all registered finalizers
in reverse order of registration.
raw docstring

launch-sync!clj/s

(launch-sync! layer)
(launch-sync! layer opts)

Starts a layer synchronously, registers a JVM shutdown hook to clean up on process termination, and optionally blocks if :join? true in opts.

Starts a layer synchronously, registers a JVM shutdown hook to clean up on process termination,
and optionally blocks if `:join? true` in `opts`.
raw docstring

layer?clj/s

(layer? x)

Returns true if x implements ILayer.

Returns true if `x` implements `ILayer`.
raw docstring

LayerSystemcljs


make-map>clj/s

(make-map> acquire-eff release-fn)

Creates a lifecycle-managed layer providing a map of services. acquire-eff is an Effect returning a context map. release-fn is a pure function (fn [context-map] -> Effect) returning an Effect to release the resources.

Creates a lifecycle-managed layer providing a map of services.
`acquire-eff` is an `Effect` returning a context map.
`release-fn` is a pure function `(fn [context-map] -> Effect)` returning an `Effect` to release the resources.
raw docstring

make-scopeclj/s

(make-scope)

Creates a fresh, empty IScope instance.

Creates a fresh, empty `IScope` instance.
raw docstring

make>clj/s

(make> key acquire-eff release-fn)

Creates a lifecycle-managed layer for a single service key. acquire-eff is an Effect returning the resource. release-fn is a pure function (fn [resource] -> Effect) returning an Effect to release the resource.

Creates a lifecycle-managed layer for a single service `key`.
`acquire-eff` is an `Effect` returning the resource.
`release-fn` is a pure function `(fn [resource] -> Effect)` returning an `Effect` to release the resource.
raw docstring

merge>clj/s

(merge>)
(merge> layer)
(merge> l1 l2)
(merge> l1 l2 & more)

Merges multiple layers horizontally. Layers are evaluated independently and their resulting context maps are merged. Resources are released in reverse acquisition order.

Merges multiple layers horizontally. Layers are evaluated independently and their
resulting context maps are merged. Resources are released in reverse acquisition order.
raw docstring

provide-layer>clj/s

(provide-layer> layer)
(provide-layer> effect layer)

Executes effect within the context provided by layer, deterministically releasing all acquired layer resources upon completion.

Supports standalone and thread-first pipeline usage: (-> (fx/service> :http/server) (fx-layer/provide-layer> app-layer))

(fx-layer/provide-layer> (fx/service> :http/server) app-layer)

Executes `effect` within the context provided by `layer`, deterministically
releasing all acquired layer resources upon completion.

Supports standalone and thread-first pipeline usage:
  (-> (fx/service> :http/server)
      (fx-layer/provide-layer> app-layer))

  (fx-layer/provide-layer> (fx/service> :http/server) app-layer)
raw docstring

start-layer!clj/s

(start-layer! layer)
(start-layer! layer initial-context)

Starts a layer synchronously, returning an active LayerSystem record containing the initialized :context and implementing java.io.Closeable.

Starts a layer synchronously, returning an active `LayerSystem` record containing
the initialized `:context` and implementing `java.io.Closeable`.
raw docstring

stop-layer!clj/s

(stop-layer! system)

Stops an active system, deterministically executing all layer finalizers in reverse order.

Stops an active system, deterministically executing all layer finalizers in reverse order.
raw docstring

with-layer>clj/s

(with-layer> layer use-eff-fn)

Executes use-eff-fn (a function (fn [context] -> Effect)) within the context of layer, guaranteeing complete teardown of all acquired layer resources upon completion.

Executes `use-eff-fn` (a function `(fn [context] -> Effect)`) within the context of `layer`,
guaranteeing complete teardown of all acquired layer resources upon completion.
raw 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