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

Class task

include/stdexec/__detail/__task.hpp:270–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268 // STDEXEC::task
269 template <class _Ty = void, class _TaskEnv = env<>>
270 class [[nodiscard]] task
271 {
272 struct __promise;
273 template <class _Env>
274 using __own_env_t = __task::__environment_type<_TaskEnv, _Env>;
275 public:
276 using sender_concept = sender_tag;
277 using promise_type = __promise;
278 using allocator_type = __task::__allocator_type<_TaskEnv>;
279 using start_scheduler_type = __task::__start_scheduler_type<_TaskEnv>;
280 using stop_source_type = __task::__stop_source_type<_TaskEnv>;
281 using stop_token_type = __task::__stop_source_token_t<stop_source_type>;
282 using error_types = __task::__error_types<_TaskEnv>;
283
284 constexpr task(task&& __that) noexcept
285 : __coro_(std::exchange(__that.__coro_, {}))
286 {}
287
288 constexpr ~task()
289 {
290 if (__coro_)
291 STDEXEC::__coroutine_destroy_nothrow(__coro_);
292 }
293
294 [[nodiscard]]
295 constexpr auto get_env() const noexcept
296 {
297 return __attrs{};
298 }
299
300 // This transforms a task into an __awaiter that can perform symmetric transfer when
301 // co_awaited.
302 template <class _ParentPromise>
303 requires __task::__has_compatible_environment_with<env_of_t<_ParentPromise&>, _TaskEnv>
304 [[nodiscard]]
305 constexpr auto as_awaitable(_ParentPromise& __parent) && noexcept
306 {
307 return __awaiter<_ParentPromise>(static_cast<task&&>(*this), __parent);
308 }
309
310 private:
311 using __on_stopped_t = __forward_stop_request<stop_source_type>;
312 using __stop_variant_t = __variant<stop_source_type, stop_token_type>;
313
314 template <class _Env>
315 using __stop_callback_t = stop_callback_for_t<stop_token_of_t<_Env>, __on_stopped_t>;
316
317 template <class _Env>
318 using __stop_callback_box_t = __task::__stop_callback_box_t<_Env, stop_source_type>;
319
320 template <class _Env>
321 static constexpr bool __needs_stop_callback =
322 __not_same_as<stop_token_type, stop_token_of_t<_Env>>;
323
324 template <class _Env>
325 static constexpr bool __nothrow_callback_registration = noexcept(
326 __declval<__stop_callback_box_t<_Env>&>()
327 .__register_callback(__declval<_Env&>(), __declval<__stop_variant_t&>()));

Callers

nothing calls this directly

Calls 3

__awaiter_baseClass · 0.85
get_envFunction · 0.70
__register_callbackMethod · 0.45

Tested by

no test coverage detected