gen-server behaviour and related functions.
gen-server behaviour and related functions.
(call server request)
(call server request timeout-ms)
The same as call!
but returns async value.
The same as `call!` but returns async value.
(call! server request)
(call! server request timeout-ms)
Makes a synchronous call to a server
by sending a request
and
waiting until a reply arrives or a time-out occurs. The handle-call
callback of the gen-server is called to handle the request.
server
can be a pid or a registered name.
request
is any form that is passed as the request
arguments to
handle-call
.
timeout-ms
is an integer greater than zero that specifies how many
milliseconds to wait for a reply, or the keyword :infinity
to wait
indefinitely. Defaults to 5000. If no reply is received within the
specified time, the function call fails.
If the caller catches the failure and continues running, and the server
is just late with the reply, it can arrive at any time later into the
message queue of the caller. The caller must in this case be prepared
for this and discard any such garbage messages that are two element
tuples with a reference as the first element.
The return value is defined in the return value of handle-call
.
The call can fail for many reasons, including time-out and the called gen-server process dying before or during the call.
Makes a synchronous call to a `server` by sending a `request` and waiting until a reply arrives or a time-out occurs. The `handle-call` callback of the gen-server is called to handle the request. `server` can be a pid or a registered name. `request` is any form that is passed as the `request` arguments to `handle-call`. `timeout-ms` is an integer greater than zero that specifies how many milliseconds to wait for a reply, or the keyword `:infinity` to wait indefinitely. Defaults to 5000. If no reply is received within the specified time, the function call fails. If the caller catches the failure and continues running, and the server is just late with the reply, it can arrive at any time later into the message queue of the caller. The caller must in this case be prepared for this and discard any such garbage messages that are two element tuples with a reference as the first element. The return value is defined in the return value of `handle-call`. The call can fail for many reasons, including time-out and the called gen-server process dying before or during the call.
(call!! server request)
(call!! server request timeout-ms)
The same as call!
but returns sync value.
The same as `call!` but returns sync value.
(cast server request)
Sends an asynchronous request to the server
and returns immediately,
ignoring if the server
process does not exist. The handle-cast
callback of the gen-server is called to handle the request.
request
is any form that is passed as the request
argument to
handle-cast
.
Sends an asynchronous request to the `server` and returns immediately, ignoring if the `server` process does not exist. The `handle-cast` callback of the gen-server is called to handle the request. `request` is any form that is passed as the `request` argument to `handle-cast`.
(handle-call _ request from state)
(handle-cast _ request state)
(handle-info _ request state)
(init _ args)
(terminate _ reason state)
(reply [mref pid :as _from] response)
This function can be used to explicitly send a reply to a client
that called call*
or, when the reply cannot be defined in the
return value of handle-call
. This allows processing call*
requests
asynchronously.
Client must be the from
argument provided to the handle-call
callback. reply
is given back to the client as the return value
of call*
.
The return value is not further defined, and is always to be ignored.
This function can be used to explicitly send a reply to a client that called `call*` or, when the reply cannot be defined in the return value of `handle-call`. This allows processing `call*` requests asynchronously. Client must be the `from` argument provided to the `handle-call` callback. `reply` is given back to the client as the return value of `call*`. The return value is not further defined, and is always to be ignored.
(start server)
(start server args)
(start server args options)
(start reg-name server args options)
The same as start!
but returns async value.
The same as `start!` but returns async value.
(start! server)
(start! server args)
(start! server args options)
(start! reg-name server args options)
Starts the server, passing args
to server's init
function.
Arguments:
server-impl
- IGenServer
implementation, or map, or namespace.
args
- any form that is passed as the argument to init function.
Options:
:timeout
- time in milliseconds gen-server is allowed to spend
initializing or it is terminated and the start function returns
[:error :timeout]
.
:spawn-opt
- options used to spawn the gen-server process (see
process/spawn-opt
)
Returns:
[:ok pid]
if server started successfully,
[:error :no-init]
if server implementation doesn't provide init
function,
[:error [:bad-return-value value]]
if init
returns a bad value,
[:error reason]
otherwise.
Throws on invalid arguments, or when the name is already registered.
Starts the server, passing `args` to server's `init` function. Arguments: `server-impl` - `IGenServer` implementation, or map, or namespace. `args` - any form that is passed as the argument to init function. Options: `:timeout` - time in milliseconds gen-server is allowed to spend initializing or it is terminated and the start function returns `[:error :timeout]`. `:spawn-opt` - options used to spawn the gen-server process (see `process/spawn-opt`) Returns: `[:ok pid]` if server started successfully, `[:error :no-init]` if server implementation doesn't provide `init` function, `[:error [:bad-return-value value]]` if `init` returns a bad value, `[:error reason]` otherwise. Throws on invalid arguments, or when the name is already registered.
(start!! server)
(start!! server args)
(start!! server args options)
(start!! reg-name server args options)
The same as start!
but returns sync value.
The same as `start!` but returns sync value.
(start-link server)
(start-link server args)
(start-link server args options)
(start-link reg-name server args options)
The same as start-link!
but returns async value.
The same as `start-link!` but returns async value.
(start-link! server)
(start-link! server args)
(start-link! server args options)
(start-link! reg-name server args options)
The same as start!
but atomically links caller to started process.
The same as `start!` but atomically links caller to started process.
(start-link!! server)
(start-link!! server args)
(start-link!! server args options)
(start-link!! reg-name server args options)
The same as start!!
but atomically links caller to started process.
The same as `start!!` but atomically links caller to started process.
(start-link-ns)
(start-link-ns args)
(start-link-ns args options)
(start-link-ns reg-name args options)
The same as start-link-ns!
but returns async value.
The same as `start-link-ns!` but returns async value.
(start-link-ns!)
(start-link-ns! args)
(start-link-ns! args options)
(start-link-ns! reg-name args options)
The same as start-ns!
but atomically links caller to started
process.
The same as `start-ns!` but atomically links caller to started process.
(start-ns)
(start-ns args)
(start-ns args options)
(start-ns reg-name args options)
The same as start-ns!
but returns async value.
The same as `start-ns!` but returns async value.
(start-ns!)
(start-ns! args)
(start-ns! args options)
(start-ns! reg-name args options)
Starts the server, taking current ns as an implementation source.
See start!
for more info.
Starts the server, taking current ns as an implementation source. See `start!` for more info.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close