FSL.Valet (fsl v0.2.0)

Copy Markdown View Source

FSL.Valet turns any synchronous processing that takes time into an asynchronous one whose result is delivered as a single tagged message to the caller.

ask/4 spawns a disposable coordinator that owns a monitored worker running fun. A single receive/after serializes the worker result against the timeout, so there is no race and exactly one message is sent back to the caller before the coordinator terminates — no late message can ever leak:

{tag, result}                      # whatever `fun` returned, verbatim
{tag, {:error, :timeout}}          # `timeout` elapsed; the worker was killed
{tag, {:error, {:crash, reason}}}  # the worker died before returning

args is the list of positional arguments applied to fun (apply(fun, args)), so its length must match the function's arity.

Summary

Functions

Run apply(fun, args) asynchronously, bounding the whole operation to timeout milliseconds. Returns the coordinator pid immediately; the caller is never blocked. The result is delivered to the calling process as a single {tag, result} message (see the module doc for the shapes).

Functions

ask(tag, fun, args, timeout)

@spec ask(term(), function(), list(), pos_integer()) :: pid()

Run apply(fun, args) asynchronously, bounding the whole operation to timeout milliseconds. Returns the coordinator pid immediately; the caller is never blocked. The result is delivered to the calling process as a single {tag, result} message (see the module doc for the shapes).