Mailglass.Outbound.AsyncAdapter behaviour (Mailglass v2.5.0)

Copy Markdown View Source

Internal behaviour for non-durable asynchronous dispatch.

Dispatch returns {:ok, pid()} or :ok only after work admission succeeds. A refusal is returned as {:error, reason} and callers must project that failure instead of acknowledging queued work.

Summary

Functions

Dispatches fun via the configured async adapter impl.

Callbacks

dispatch(fun, opts)

@callback dispatch(fun :: (-> any()), opts :: keyword()) ::
  {:ok, pid()} | :ok | {:error, term()}

Functions

dispatch(fun, opts \\ [])

@spec dispatch(
  (-> any()),
  keyword()
) :: {:ok, pid()} | :ok | {:error, term()}

Dispatches fun via the configured async adapter impl.

The caller is responsible for stamping tenant context inside the closure via Mailglass.Tenancy.with_tenant/2 before calling this function — the tenancy re-stamp works for both impls (-15):

  • TaskSupervisor: spawns a fresh process; with_tenant/2 stamps it.
  • Inline: runs synchronously in the caller's process; with_tenant/2 re-stamps and restores on return.