[task.state] # 33 Execution control library [[exec]](./#exec) ## 33.13 Coroutine utilities [[exec.coro.util]](exec.coro.util#task.state) ### 33.13.6 execution​::​task [[exec.task]](exec.task#task.state) #### 33.13.6.4 Class template task​::​*state* [task.state] namespace std::execution {templatetemplate<[receiver](exec.recv.concepts#concept:receiver "33.7.1 Receiver concepts [exec.recv.concepts]") Rcvr>class task::*state* { // *exposition only*public:using operation_state_concept = operation_state_t; template*state*(coroutine_handle h, R&& rr); ~*state*(); void start() & noexcept; private:using *own-env-t* = *see below*; // *exposition only* coroutine_handle *handle*; // *exposition only* remove_cvref_t *rcvr*; // *exposition only**own-env-t* *own-env*; // *exposition only* Environment *environment*; // *exposition only*};} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7336) The type *own-env-t* is Environment​::​template env_type(​)))​> if that[*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type, env<> otherwise[.](#1.sentence-1) [🔗](#lib:task::state,constructor) `template state(coroutine_handle h, R&& rr); ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7347) *Effects*: Initializes - [(2.1)](#2.1) *handle* with std​::​move(h); - [(2.2)](#2.2) *rcvr* with std​::​forward(rr); - [(2.3)](#2.3) *own-env* with *own-env-t*(get_env(*rcvr*)) if that expression is valid and *own-env-t*() otherwise[.](#2.3.sentence-1) If neither of these expressions is valid, the program is ill-formed[.](#2.3.sentence-2) - [(2.4)](#2.4) *environment* withEnvironment(*own-env*) if that expression is valid, otherwise Environment(​get_env(*rcvr*)) if this expression is valid, otherwise Environment()[.](#2.4.sentence-1) If neither of these expressions is valid, the program is ill-formed[.](#2.4.sentence-2) [🔗](#lib:task::state,destructor) `~state(); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7370) *Effects*: Equivalent to:if (*handle*)*handle*.destroy(); [🔗](#lib:start,task::state) `void start() & noexcept; ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L7384) *Effects*: Let *prom* be the object *handle*.promise()[.](#4.sentence-1) Associates *STATE*(*prom*), *RCVR*(*prom*), and *SCHED*(*prom*) with *this as follows: - [(4.1)](#4.1) *STATE*(*prom*) is *this[.](#4.1.sentence-1) - [(4.2)](#4.2) *RCVR*(*prom*) is *rcvr*[.](#4.2.sentence-1) - [(4.3)](#4.3) *SCHED*(*prom*) is the object initialized with scheduler_type(get_scheduler(get_env(*rcvr*))) if that expression is valid and scheduler_type() otherwise[.](#4.3.sentence-1) If neither of these expressions is valid, the program is ill-formed[.](#4.3.sentence-2) Let *st* be get_stop_token(get_env(*rcvr*))[.](#4.sentence-3) Initializes *prom*.*token* and*prom*.*source* such that - [(4.4)](#4.4) *prom*.*token*.stop_requested() returns*st*.stop_requested(); - [(4.5)](#4.5) *prom*.*token*.stop_possible() returns*st*.stop_possible(); and - [(4.6)](#4.6) for types Fn and Init such that both[invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]") and[constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]") are modeled,stop_token_type​::​callback_type models[*stoppable-callback-for*](stoptoken.concepts#concept:stoppable-callback-for "32.3.3 Stop token concepts [stoptoken.concepts]")[.](#4.sentence-4) After that invokes *handle*.resume()[.](#4.sentence-5)