Liking cljdoc? Tell your friends :D

loom-otp.gen-server

Generic server behavior implementation.

Provides a standard way to implement servers with synchronous calls, asynchronous casts, and message handling.

Generic server behavior implementation.

Provides a standard way to implement servers with synchronous calls,
asynchronous casts, and message handling.
raw docstring

callclj

(call server request)
(call server request timeout-ms)

Make synchronous call to server. Returns response or throws on timeout/error.

Make synchronous call to server. Returns response or throws on timeout/error.
sourceraw docstring

castclj

(cast server request)

Send asynchronous request to server. Returns :ok.

Send asynchronous request to server. Returns :ok.
sourceraw docstring

IGenServercljprotocol

Protocol for gen_server callbacks.

Protocol for gen_server callbacks.

handle-callclj

(handle-call this request from state)

Handle synchronous call. Returns: [:reply response new-state] | [:reply response new-state timeout] | [:noreply new-state] | [:noreply new-state timeout] | [:stop reason response new-state] | [:stop reason new-state]

Handle synchronous call.
Returns: [:reply response new-state]
       | [:reply response new-state timeout]
       | [:noreply new-state]
       | [:noreply new-state timeout]
       | [:stop reason response new-state]
       | [:stop reason new-state]

handle-castclj

(handle-cast this request state)

Handle asynchronous cast. Returns: [:noreply new-state] | [:noreply new-state timeout] | [:stop reason new-state]

Handle asynchronous cast.
Returns: [:noreply new-state]
       | [:noreply new-state timeout]
       | [:stop reason new-state]

handle-infoclj

(handle-info this message state)

Handle other messages. Returns: same as handle-cast

Handle other messages.
Returns: same as handle-cast

initclj

(init this args)

Initialize server state. Returns: [:ok state] | [:ok state timeout] | [:stop reason]

Initialize server state.
Returns: [:ok state] | [:ok state timeout] | [:stop reason]

terminateclj

(terminate this reason state)

Called when server is terminating. Return value ignored.

Called when server is terminating. Return value ignored.
sourceraw docstring

ns->gen-serverclj

(ns->gen-server ns-sym)

Create an IGenServer implementation from a namespace.

The namespace should define functions matching the IGenServer protocol:

  • init [args] -> [:ok state] | [:ok state timeout] | [:stop reason]
  • handle-call [request from state] -> [:reply response new-state] | ...
  • handle-cast [request state] -> [:noreply new-state] | ...
  • handle-info [message state] -> [:noreply new-state] | ...
  • terminate [reason state] -> ignored

Missing functions use default implementations.

Usage: (ns my-server) (defn init [args] [:ok {:count 0}]) (defn handle-call [req from state] [:reply (:count state) state])

;; Then start with: (gen-server/start (gen-server/ns->gen-server 'my-server))

Create an IGenServer implementation from a namespace.

The namespace should define functions matching the IGenServer protocol:
- init [args] -> [:ok state] | [:ok state timeout] | [:stop reason]
- handle-call [request from state] -> [:reply response new-state] | ...
- handle-cast [request state] -> [:noreply new-state] | ...
- handle-info [message state] -> [:noreply new-state] | ...
- terminate [reason state] -> ignored

Missing functions use default implementations.

Usage:
(ns my-server)
(defn init [args] [:ok {:count 0}])
(defn handle-call [req from state] [:reply (:count state) state])

;; Then start with:
(gen-server/start (gen-server/ns->gen-server 'my-server))
sourceraw docstring

replyclj

(reply [ref caller-pid] response)

Send reply to a call. Used when handle-call returns :noreply. from is [ref caller-pid].

Send reply to a call. Used when handle-call returns :noreply.
from is [ref caller-pid].
sourceraw docstring

startclj

(start impl)
(start impl args)
(start impl args opts)

Start a gen_server process. Returns {:ok pid} or {:error reason}.

Start a gen_server process.
Returns {:ok pid} or {:error reason}.
sourceraw docstring

(start-link impl)
(start-link impl args)
(start-link impl args opts)

Start a gen_server process linked to current process. Returns {:ok pid} or {:error reason}.

Start a gen_server process linked to current process.
Returns {:ok pid} or {:error reason}.
sourceraw docstring

stopclj

(stop server)
(stop server reason)
(stop server reason timeout)

Stop the server.

Stop the server.
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