clj-r2dbc.impl.util

Internal utilities for Missionary task bridging and Reactive Streams collection.

Provides:
  to-task      - lifts a stage return value into a Missionary task.
  void->task   - bridges a Publisher<Void> into a Missionary task.
  collect-pub  - subscribes to a Publisher and collects all emitted values into a vector.
  elapsed-ms   - returns milliseconds elapsed since a System/nanoTime snapshot.

These are implementation details; do not use from application code.

collect-pub

(collect-pub pub)
Return a Missionary task that subscribes to pub and collects all emitted values.

Requests Long/MAX_VALUE from the Subscription so the Publisher can emit
all values without back-pressure stalls. Uses CompletableFuture + m/via m/blk
to avoid blocking the Missionary scheduler thread.

Unwraps ExecutionException from CompletableFuture.get() so callers see the
original exception type. On Missionary cancellation, cancels upstream.

Args:
  pub - Publisher to collect from.

Returns a Missionary task resolving to a vector of all emitted values.

elapsed-ms

(elapsed-ms t0)
Return the milliseconds elapsed since the nanoTime snapshot t0 as a primitive double.

Args:
  t0 - long value from a prior (System/nanoTime) call.

to-task

(to-task result)
Lift a pipeline stage return value into a Missionary task.

When result is already a function (satisfies the Missionary task contract:
a 2-arity fn returning a cancel-fn), it is returned as-is. Otherwise, the
value is wrapped in (m/sp value) to produce a task that immediately resolves.

Allows interceptor handlers to return either a plain context map
(synchronous, minimal allocation) or an m/sp task (async, cancellable).

Args:
  result - interceptor return value: a context map or a Missionary task.

void->task

(void->task pub)
Return a Missionary task that resolves to nil when pub completes, or rejects on error.

Used to bridge R2DBC lifecycle methods that return Publisher<Void>
(e.g., beginTransaction, commitTransaction, rollbackTransaction,
Connection.close) into Missionary tasks.

m/subscribe converts the Publisher into a discrete flow; m/reduce drains
it. Since Publisher<Void> emits no values, the result is always nil.

Args:
  pub - Publisher<Void> to drain.