Internal helpers for the dgen_server call/reply protocol.
This module implements the client-side call flow: pushing a call request onto the durable queue, waiting for the reply via a watch, and cleaning up reply keys on timeout.
Reply payloads are stored using the codec's chunked term encoding so that
replies can exceed the single-value size limit. The watch is placed on
the first chunk key; the client always reads via get_range.
Call Request Flow
- The caller invokes
dgen_server:call/3which delegates tocall/4. - A call request is pushed onto the durable queue via
push_call/5, which writesnoreplyas a chunked term under the from-key and sets a watch on the first chunk key. - The caller blocks in
await_call_reply/4until the watch fires or the timeout expires. - A consumer processes the request and writes
{reply, Reply}as a chunked term under the from-key. - The watch fires, the caller reads and clears the chunked reply.
- On timeout the caller clears the chunked reply keys to avoid leaks.
Summary
Functions
Sends a synchronous call through the durable queue and waits for the reply.
Builds a from-key tuple from a waiting key and a unique ref.
Appends the <<"c">> waiting-key tag to a tuid tuple.
Pushes a call request onto the durable queue.
Like push_call/6 but records Attempts as the initial attempt count in the
message envelope. Pass a non-zero value when the call has already failed at
least once (e.g. after an inline execution attempt) so the dead-letter
threshold accounts for all failures.
Types
Functions
-spec call(module(), gen_server:server_ref(), term(), timeout()) -> term().
Sends a synchronous call through the durable queue and waits for the reply.
Module is the gen_server-compatible module used to send the initial message
(typically gen_server). On timeout, the reply keys are cleared to prevent
durable key leaks.
-spec get_from(dgen_backend:tuple_key(), reference()) -> from().
Builds a from-key tuple from a waiting key and a unique ref.
The key includes a system-time timestamp (seconds) so that abandoned
call keys can be garbage-collected using a time-based heuristic.
Key structure: {WaitingKey..., Timestamp, term_to_binary(Ref)}.
-spec get_waiting_key(tuid()) -> dgen_backend:tuple_key().
Appends the <<"c">> waiting-key tag to a tuid tuple.
-spec push_call(term(), tuid(), dgen_queue:quid(), term(), pid(), list()) -> {from(), dgen_backend:future()}.
Pushes a call request onto the durable queue.
Writes noreply as a chunked term under the from-key prefix, sets a
watch on the first chunk key directed to WatchTo, and enqueues the request.
Returns {From, Watch} where From is the from-key tuple.
-spec push_call(term(), tuid(), dgen_queue:quid(), term(), pid(), list(), non_neg_integer()) -> {from(), dgen_backend:future()}.
Like push_call/6 but records Attempts as the initial attempt count in the
message envelope. Pass a non-zero value when the call has already failed at
least once (e.g. after an inline execution attempt) so the dead-letter
threshold accounts for all failures.