Skip to content

Commit

Permalink
Fix cancellation token
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Sep 4, 2023
1 parent 840d737 commit a911f46
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/circular_queue/cancellation_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ namespace ghostl
/// cancellation_token_source is cancelled. Never call this more than once
/// on the same cancellation_token, but get another cancellation token.
/// </summary>
/// <returns></returns>
/// <returns>A bool task, that has a value of true if cancellation occured,
/// or false if the cancellation source etc was deleted without cancellation.</returns>
[[nodiscard]] auto cancellation_request() -> ghostl::task<bool>
{
if (!state || state->is_cancellation_requested()) co_return true;
tcs_node = state->make_tcs_list_node();
// if concurrently cancelled, re-cancel to force processing of the new token.
if (state->is_cancellation_requested()) state->cancel();
co_return co_await tcs_node->item.token();
auto cancelled = co_await tcs_node->item.token();
tcs_node = nullptr;
co_return cancelled;
}
};

Expand Down

0 comments on commit a911f46

Please sign in to comment.