Imp.Tasks (Imp v0.5.0)

Copy Markdown View Source

Tasks that carry the caller's Imp context.

async/1 and async_nolink/1 start a supervised task that runs with the settings, Imp.Run context, telemetry context and Imp.Deadline of the process that started it, so a model call or tool event inside the task belongs to the caller's run, reads the caller's Imp.configure/1 and Imp.context/2 settings, and has its model requests capped to the caller's deadline. A plain Task does not carry them.

Every such task takes a place in one machine-wide pool bounded by the :async_max_workers setting, and waits for a place when the pool is full. The caller's deadline does not bound that wait. A host that bounds its own runs passes admission: {pool, limit} to Imp.Run.start/3 instead.

Summary

Functions

Starts a linked supervised task that carries the caller's settings, run and telemetry context.

Starts an unlinked supervised task that carries the caller's settings, run and telemetry context. Await it with Task.yield/2 or Task.await/2.

Functions

async(fun)

@spec async((-> term())) :: Task.t()

Starts a linked supervised task that carries the caller's settings, run and telemetry context.

iex> task = Imp.context([task_marker: :inside], fn ->
...>   Imp.Tasks.async(fn -> Imp.Settings.fetch!(:task_marker) end)
...> end)
iex> Task.await(task)
:inside

async_nolink(fun)

@spec async_nolink((-> term())) :: Task.t()

Starts an unlinked supervised task that carries the caller's settings, run and telemetry context. Await it with Task.yield/2 or Task.await/2.