Example GenServer implementation of Querier
using Zenohex.Session.declare_querier/3.
This example demonstrates how to reuse a declared querier for multiple queries.
For the actual implementation, please refer to the following,
Examples
Assumes a matching queryable is already running and replies on key/expr/**.
iex> {:ok, session_id} = Zenohex.Session.open()
iex> {:ok, _querier_pid} =
...> Zenohex.Examples.Querier.start_link(
...> session_id: session_id,
...> key_expr: "key/expr/**"
...> )
iex> Zenohex.Examples.Querier.get(timeout: 1_000)
{:ok, [%Zenohex.Sample{key_expr: "key/expr/1", payload: "reply"}]}
Summary
Functions
Executes a query with the declared querier.
Starts Elixir.Zenohex.Examples.Querier.
Stops Elixir.Zenohex.Examples.Querier
Types
@type get_opts() :: [ timeout: non_neg_integer(), attachment: binary() | nil, encoding: String.t(), parameters: String.t(), payload: binary() | nil ]
Functions
@spec get(get_opts()) :: {:ok, [Zenohex.Sample.t() | Zenohex.Query.ReplyError.t()]} | {:error, :timeout} | {:error, reason :: term()}
Executes a query with the declared querier.
The timeout used here controls how long the Elixir side waits while collecting
replies. To configure the network-side query timeout, pass query_timeout: in
:querier_opts when starting the server.
@spec get(GenServer.server(), get_opts()) :: {:ok, [Zenohex.Sample.t() | Zenohex.Query.ReplyError.t()]} | {:error, :timeout} | {:error, reason :: term()}
@spec start_link( session_id: Zenohex.Session.id(), key_expr: String.t(), name: GenServer.name(), querier_opts: Zenohex.Session.querier_opts() ) :: GenServer.on_start()
Starts Elixir.Zenohex.Examples.Querier.
Parameters
args– a keyword list that can include the following keys::session_id– the ID of the session:key_expr– the key expression to query:querier_opts– options passed toZenohex.Session.declare_querier/3
@spec stop(GenServer.server()) :: :ok | {:error, reason :: term()}
Stops Elixir.Zenohex.Examples.Querier