MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / basic_task

Class basic_task

include/exec/task.hpp:498–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496 // basic_task
497 template <class _Ty, class _Context = default_task_context<_Ty>>
498 class [[nodiscard]] basic_task
499 {
500 struct __promise;
501
502 template <class _ParentPromise>
503 struct __task_awaiter;
504
505 using __promise_context_t = _Context::template promise_context_t<__promise>;
506
507 public:
508 using promise_type = __promise;
509
510 constexpr basic_task(basic_task&& __that) noexcept
511 : __coro_(std::exchange(__that.__coro_, {}))
512 {}
513
514 // Make this task awaitable within a particular context:
515 template <class _ParentPromise>
516 requires __std::constructible_from<awaiter_context_t<__promise, _ParentPromise>,
517 __promise_context_t&,
518 _ParentPromise&>
519 constexpr auto as_awaitable(_ParentPromise&) && noexcept -> __task_awaiter<_ParentPromise>
520 {
521 return __task_awaiter<_ParentPromise>{std::exchange(__coro_, {})};
522 }
523
524 // Make this task generally awaitable:
525 constexpr auto operator co_await() && noexcept -> __task_awaiter<void>
526 requires __minvocable_q<awaiter_context_t, __promise>
527 {
528 return __task_awaiter<void>{std::exchange(__coro_, {})};
529 }
530
531 constexpr ~basic_task()
532 {
533 if (__coro_)
534 STDEXEC::__coroutine_destroy_nothrow(__coro_);
535 }
536
537 private:
538 using __scheduler_t =
539 __call_result_or_t<get_start_scheduler_t, STDEXEC::inline_scheduler, _Context>;
540
541 struct __final_awaiter
542 {
543 static constexpr auto await_ready() noexcept -> bool
544 {
545 return false;
546 }
547
548 static constexpr auto await_suspend(__std::coroutine_handle<__promise> __h) noexcept //
549 -> __std::coroutine_handle<>
550 {
551 return __h.promise().continuation().handle();
552 }
553
554 static constexpr void await_resume() noexcept {}
555 };

Callers 1

get_return_objectMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected