class TaskBase

Defined at line 60 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

Holds context for a task and its handler, with RAII semantics.

Automatically cancels the task when it goes out of scope.

After successfully posting the task, the client is responsible for retaining

the structure in memory (and unmodified) until the task's handler runs, the task

is successfully canceled, or the dispatcher shuts down. Thereafter, the task

may be posted again or destroyed.

This class must only be used with single-threaded asynchronous dispatchers

and must only be accessed on the dispatch thread since it lacks internal

synchronization of its state.

Concrete implementations: |async::Task|, |async::TaskMethod|,

|async::TaskClosure|, |async::TaskClosureMethod|.

Please do not create subclasses of TaskBase outside of this library.

Public Methods

zx_status_t Post (async_dispatcher_t * dispatcher)

Posts a task to invoke the handler with a deadline of now.

Returns |ZX_OK| if the task was successfully posted.

Returns |ZX_ERR_BAD_STATE| if the dispatcher is shutting down.

Returns |ZX_ERR_ALREADY_EXISTS| if the task is already pending.

Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher.

Defined at line 61 of file ../../sdk/lib/async/task.cc

zx_status_t PostDelayed (async_dispatcher_t * dispatcher, zx::duration delay)

Posts a task to invoke the handler with a deadline expressed as a |delay| from now.

Returns |ZX_OK| if the task was successfully posted.

Returns |ZX_ERR_BAD_STATE| if the dispatcher is shutting down.

Returns |ZX_ERR_ALREADY_EXISTS| if the task is already pending.

Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher.

Defined at line 65 of file ../../sdk/lib/async/task.cc

zx_status_t PostForTime (async_dispatcher_t * dispatcher, zx::time deadline)

Posts a task to invoke the handler with the specified |deadline|.

The |deadline| must be expressed in the time base used by the asynchronous

dispatcher (usually |ZX_CLOCK_MONOTONIC| except in unit tests).

See |async_now()| for details.

Returns |ZX_OK| if the task was successfully posted.

Returns |ZX_ERR_BAD_STATE| if the dispatcher is shutting down.

Returns |ZX_ERR_ALREADY_EXISTS| if the task is already pending.

Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher.

Defined at line 69 of file ../../sdk/lib/async/task.cc

bool is_pending ()

Returns true if the task has been posted and has not yet executed or been canceled.

Defined at line 72 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

zx::time last_deadline ()

The last deadline with which the task was posted, or |zx::time::infinite()|

if it has never been posted.

Defined at line 76 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

zx_status_t Cancel ()

Cancels the task.

If successful, the task's handler will not run.

Returns |ZX_OK| if the task was pending and it has been successfully

canceled; its handler will not run again and can be released immediately.

Returns |ZX_ERR_NOT_FOUND| if task was not pending either because its

handler already ran, or the task had not been posted.

Returns |ZX_ERR_NOT_SUPPORTED| if not supported by the dispatcher.

Defined at line 82 of file ../../sdk/lib/async/task.cc

Protected Methods

void TaskBase (async_task_handler_t * handler)

Defined at line 50 of file ../../sdk/lib/async/task.cc

void ~TaskBase ()

Defined at line 53 of file ../../sdk/lib/async/task.cc

void TaskBase (const TaskBase & )

Defined at line 65 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

void TaskBase (TaskBase && )

Defined at line 66 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

TaskBase & operator= (const TaskBase & )

Defined at line 67 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

TaskBase & operator= (TaskBase && )

Defined at line 68 of file ../../sdk/lib/async/include/lib/async/cpp/task.h

template <typename T>
T * Dispatch (async_task_t * task)

Defined at line 119 of file ../../sdk/lib/async/include/lib/async/cpp/task.h