adk_task (erlang_adk v0.7.0)

View Source

Public API for bounded supervised work.

Task references are stable binaries. Work is owned by adk_task_worker under adk_task_sup, not by the process that starts or awaits it. A task has exactly one outcome:

{completed, Value} {failed, Reason} {timed_out, deadline_exceeded} {cancelled, Reason}

The deadline option is an absolute Erlang monotonic millisecond value. A relative timeout is converted to that absolute deadline once, before the supervised task starts, so queue/startup time consumes the same budget.

Summary

Types

outcome/0

-type outcome() ::
          {completed, term()} | {failed, term()} | {timed_out, deadline_exceeded} | {cancelled, term()}.

task_ref/0

-type task_ref() :: binary().

Functions

await(TaskRef)

-spec await(task_ref()) -> outcome() | {error, term()}.

await(TaskRef, Timeout)

-spec await(task_ref(), timeout()) -> outcome() | {error, term()}.

cancel(TaskRef)

-spec cancel(task_ref()) -> ok | {error, term()}.

cancel(TaskRef, Reason)

-spec cancel(task_ref(), term()) -> ok | {error, term()}.

deadline_after(Timeout)

-spec deadline_after(non_neg_integer() | infinity) -> integer() | infinity.

start(Work)

-spec start(fun(() -> term()) | {module(), atom(), [term()]}) -> {ok, task_ref()} | {error, term()}.

start(Work, Opts0)

-spec start(fun(() -> term()) | {module(), atom(), [term()]}, map()) ->
               {ok, task_ref()} | {error, term()}.

status(TaskRef)

-spec status(task_ref()) -> {ok, map()} | {error, term()}.