Pigweed
C/C++ API Reference
Home
Modules
Loading...
Searching...
No Matches
task.h
1
// Copyright 2022 The Pigweed Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
// use this file except in compliance with the License. You may obtain a copy of
5
// the License at
6
//
7
// https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
// License for the specific language governing permissions and limitations under
13
// the License.
14
#pragma once
15
16
#include <optional>
17
18
#include "pw_async/context.h"
19
#include "pw_async/task_function.h"
20
#include "pw_async_backend/task.h"
21
22
namespace
pw::async
{
23
25
26
namespace
test {
27
class
FakeDispatcher;
28
}
29
33
class
Task
final {
34
public
:
37
Task
() : native_type_(*this) {}
38
40
explicit
Task
(
TaskFunction
&& f) : native_type_(*this, std::move(f)) {}
41
42
Task
(
const
Task
&) =
delete
;
43
Task
& operator=(
const
Task
&) =
delete
;
44
Task
(
Task
&&) =
delete
;
45
Task
& operator=(
Task
&&) =
delete
;
46
49
void
set_function
(
TaskFunction
&& f) {
50
native_type_.set_function(std::move(f));
51
}
52
54
void
operator()
(
Context
& ctx,
Status
status) { native_type_(ctx, status); }
55
58
backend::NativeTask&
native_type
() {
return
native_type_; }
59
const
backend::NativeTask&
native_type
()
const
{
return
native_type_; }
60
61
private
:
62
backend::NativeTask native_type_;
63
};
64
65
}
// namespace pw::async
pw::Status
Definition:
status.h:86
pw::async::Task
Definition:
task.h:33
pw::async::Task::Task
Task(TaskFunction &&f)
Constructs a Task that calls f when executed on a Dispatcher.
Definition:
task.h:40
pw::async::Task::set_function
void set_function(TaskFunction &&f)
Definition:
task.h:49
pw::async::Task::native_type
backend::NativeTask & native_type()
Definition:
task.h:58
pw::async::Task::operator()
void operator()(Context &ctx, Status status)
Executes this task.
Definition:
task.h:54
pw::async::Task::Task
Task()
Definition:
task.h:37
pw::async::TaskFunction
Function< void(Context &, Status)> TaskFunction
Definition:
task_function.h:39
pw::async
(Deprecated) Async library
Definition:
context.h:19
pw::async::Context
Contextual information provided by a Dispatcher to a running task.
Definition:
context.h:27
pw_async
public
pw_async
task.h
Generated by
1.9.6