Module shards_task

Task utility.

Description

Task utility.

Conveniences for spawning and awaiting tasks.

This module is based on Elixir Task

Data Types

callback()

callback() = {module(), atom(), [term()]}

MFA Callback.

info()

info() = {node(), pid() | atom()}

Process info.

link()

link() = link | monitor | nolink

Process link options.

proc_info()

proc_info() = {node(), pid() | atom()}

task()

task() = #{pid => pid() | nil, ref => ref() | nil, owner => pid() | nil}

Task definition.

It contains these fields:

task_fun()

task_fun() = fun(() -> term()) | fun((term()) -> term())

Task Function.

Function Index

async/1Equivalent to async(erlang, apply, [Fun, []]).
async/2Equivalent to async(erlang, apply, [Fun, Args]).
async/3 Starts a task that must be awaited on.
await/1Equivalent to await(Task, 5000).
await/2 Awaits a task reply.
start/1 Starts a task.
start/2 Starts a task.
start/3 Starts a task.
start_link/1 Starts a task as part of a supervision tree.
start_link/2 Starts a task as part of a supervision tree.
start_link/3 Starts a task as part of a supervision tree.

Function Details

async/1

async(Fun) -> any()

Equivalent to async(erlang, apply, [Fun, []]).

async/2

async(Fun, Args) -> any()

Equivalent to async(erlang, apply, [Fun, Args]).

async/3

async(Mod::module(), Fun::atom(), Args::[term()]) -> task()

Starts a task that must be awaited on.

A task() type is returned containing the relevant information. Developers must eventually call await/2 on the returned task.

await/1

await(Task) -> any()

Equivalent to await(Task, 5000).

await/2

await(Task::task(), Timeout::timeout()) -> term() | no_return()

Awaits a task reply.

A timeout, in milliseconds, can be given with default value of 5000. In case the task process dies, this function will exit with the same reason as the task.

If the timeout is exceeded, await will exit, however, the task will continue to run. When the calling process exits, its exit signal will terminate the task if it is not trapping exits.

This function assumes the task's monitor is still active or the monitor's DOWN message is in the message queue. If it has been demonitored, or the message already received, this function may wait for the duration of the timeout awaiting the message.

This function will always exit and demonitor if the task crashes or if it times out, so the task can not be used again.

start/1

start(Fun::task_fun()) -> {ok, pid()}

Starts a task.

This is only used when the task is used for side-effects (i.e. no interest in the returned result) and it should not be linked to the current process.

start/2

start(Fun::task_fun(), Args::[term()]) -> {ok, pid()}

Starts a task.

This is only used when the task is used for side-effects (i.e. no interest in the returned result) and it should not be linked to the current process.

start/3

start(Mod::module(), Fun::atom(), Args::[term()]) -> {ok, pid()}

Starts a task.

This is only used when the task is used for side-effects (i.e. no interest in the returned result) and it should not be linked to the current process.

start_link/1

start_link(Fun::task_fun()) -> {ok, pid()}

Starts a task as part of a supervision tree.

start_link/2

start_link(Fun::task_fun(), Args::[term()]) -> {ok, pid()}

Starts a task as part of a supervision tree.

start_link/3

start_link(Mod::module(), Fun::atom(), Args::[term()]) -> {ok, pid()}

Starts a task as part of a supervision tree.


Generated by EDoc, Jul 11 2017, 14:57:01.