19#include "pw_async2/future.h"
20#include "pw_async2/poll.h"
21#include "pw_async2/task.h"
22#include "pw_function/function.h"
27template <
typename FutureType>
28using CallbackType = std::conditional_t<
29 std::is_same_v<typename FutureType::value_type, ReadyType>,
31 Function<void(
typename FutureType::value_type)>>;
42template <
typename FutureType,
43 typename Func = internal::CallbackType<FutureType>>
46 using value_type =
typename FutureType::value_type;
48 static_assert(is_future_v<FutureType>,
49 "CallbackTask can only be used with Future types");
55 future_(std::move(future)),
56 callback_(std::move(callback)) {}
64 template <
typename Callback,
typename... Args>
66 static_assert(
sizeof...(Args) >= 1u,
67 "Cannot default construct a Future with Emplace");
69 std::forward<Callback>(callback), std::forward<Args>(future_args)...);
73 template <
typename,
typename>
76 template <
typename... Args>
77 constexpr CallbackTask(Func&& callback, Args&&... future_args)
78 : future_(std::forward<Args>(future_args)...),
79 callback_(std::move(callback)) {}
87 if constexpr (std::is_same_v<value_type, ReadyType>) {
90 callback_(std::move(*poll));
100template <
typename FutureType,
typename Func>
101CallbackTask(Func&&, FutureType&&) -> CallbackTask<FutureType, Func>;
Definition: callback_task.h:44
static constexpr auto Emplace(Callback &&callback, Args &&... future_args)
Definition: callback_task.h:65
Poll DoPend(Context &cx) final
Definition: callback_task.h:81
constexpr CallbackTask(Func &&callback, FutureType &&future)
Definition: callback_task.h:53
#define PW_ASYNC_TASK_NAME(name)
Generates a token for use as a task name.
Definition: task.h:30
constexpr bool IsPending() const noexcept
Returns whether or not this value is Pending.
Definition: poll.h:136
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271
constexpr Poll Ready()
Returns a value indicating completion.
Definition: poll.h:255
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
fit::callback_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Callback
Definition: function.h:128