|
VLink
2.0.0
A high-performance communication middleware
|
Shared observable handle returned by tracked posting APIs. 更多...
#include <task_handle.h>
Public 成员函数 | |
| TaskHandle () noexcept | |
| Constructs an invalid handle that references no task. 更多... | |
| ~TaskHandle () | |
| Destroys the handle reference. 更多... | |
| TaskHandle (const TaskHandle &) noexcept | |
Copy-constructs a handle that shares state with other. 更多... | |
| TaskHandle & | operator= (const TaskHandle &) noexcept |
| Copy-assigns from another handle; both handles share state afterwards. 更多... | |
| TaskHandle (TaskHandle &&) noexcept | |
| Move-constructs a handle, transferring the shared state from the source. 更多... | |
| TaskHandle & | operator= (TaskHandle &&) noexcept |
| Move-assigns from another handle, transferring its shared state. 更多... | |
| bool | valid () const noexcept |
| Reports whether this handle refers to a live task state block. 更多... | |
| TaskExecutionState | state () const noexcept |
| Returns the current lifecycle stage of the task. 更多... | |
| bool | is_done () const noexcept |
| Reports whether the task has reached a terminal state. 更多... | |
| CancellationToken | cancellation_token () const noexcept |
| Returns the task-local cancellation token associated with this handle. 更多... | |
| bool | cancel () const |
| Requests cooperative cancellation of the task. 更多... | |
| bool | wait (int timeout_ms=kInfinite) const |
| Blocks until the task reaches a terminal state or the timeout elapses. 更多... | |
静态 Public 属性 | |
| static constexpr int | kInfinite {-1} |
Sentinel timeout value for wait() meaning wait indefinitely. 更多... | |
友元 | |
| class | MessageLoop |
| class | ThreadPool |
| class | TrackedTask |
Shared observable handle returned by tracked posting APIs.
Backed by a std::shared_ptr to an internal state block, so copies and moves all point at the same task. Provides cooperative cancellation, blocking wait on the terminal state, and a task-local CancellationToken that running callbacks can poll.
|
noexcept |
Constructs an invalid handle that references no task.
valid() returns false and state() returns TaskExecutionState::kInvalid.
| vlink::TaskHandle::~TaskHandle | ( | ) |
Destroys the handle reference.
|
noexcept |
Copy-constructs a handle that shares state with other.
|
noexcept |
Move-constructs a handle, transferring the shared state from the source.
| bool vlink::TaskHandle::cancel | ( | ) | const |
Requests cooperative cancellation of the task.
No-op when the handle is invalid or already terminal. When the task has not started running (kInvalid or kQueued) this call transitions the state to kCancelled; in any non-terminal case it also flips the cancellation source so running callbacks polling the token observe the request.
true when this call either transitioned the state or flipped the source; false when the handle was invalid or already terminal.
|
noexcept |
Returns the task-local cancellation token associated with this handle.
Running callbacks may poll this token for cooperative abort. Callbacks registered on the token fire outside the handle mutex, so they may safely re-enter the handle.
|
noexcept |
Reports whether the task has reached a terminal state.
true once state() is one of kCompleted, kCancelled, kDropped, kRejected or kFailed.
|
noexcept |
Copy-assigns from another handle; both handles share state afterwards.
*this.
|
noexcept |
Move-assigns from another handle, transferring its shared state.
*this.
|
noexcept |
Returns the current lifecycle stage of the task.
TaskExecutionState; kInvalid when the handle is not valid.
|
noexcept |
Reports whether this handle refers to a live task state block.
false when default-constructed or moved-from. | bool vlink::TaskHandle::wait | ( | int | timeout_ms = kInfinite | ) | const |
Blocks until the task reaches a terminal state or the timeout elapses.
Never throws on cancellation; inspect state() after the call to distinguish the possible outcomes.
| timeout_ms | Maximum wait in milliseconds; kInfinite waits forever. |
true when a terminal state was reached before the deadline.
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
Sentinel timeout value for wait() meaning wait indefinitely.