diff options
Diffstat (limited to 'pw_async/public/pw_async/internal/types.h')
-rw-r--r-- | pw_async/public/pw_async/internal/types.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/pw_async/public/pw_async/internal/types.h b/pw_async/public/pw_async/internal/types.h index 67b5a88c4..c8b7ea287 100644 --- a/pw_async/public/pw_async/internal/types.h +++ b/pw_async/public/pw_async/internal/types.h @@ -14,19 +14,32 @@ #pragma once #include "pw_function/function.h" +#include "pw_status/status.h" namespace pw::async { class Dispatcher; class Task; -// Task functions take a `Context` as their argument. Before executing a Task, -// the Dispatcher sets the pointer to itself and to the Task in `Context`. struct Context { Dispatcher* dispatcher; Task* task; }; -using TaskFunction = Function<void(Context&)>; +// A TaskFunction is a unit of work that is wrapped by a Task and executed on a +// Dispatcher. +// +// TaskFunctions take a `Context` as their first argument. Before executing a +// Task, the Dispatcher sets the pointer to itself and to the Task in `Context`. +// +// TaskFunctions take a `Status` as their second argument. When a Task is +// running as normal, |status| == PW_STATUS_OK. If a Task will not be able to +// run as scheduled, the Dispatcher will still invoke the TaskFunction with +// |status| == PW_STATUS_CANCELLED. This provides an opportunity to reclaim +// resources held by the Task. +// +// A Task will not run as scheduled if, for example, it is still waiting when +// the Dispatcher shuts down. +using TaskFunction = Function<void(Context&, Status)>; } // namespace pw::async |