/* * Copyright (c) Facebook, Inc. and its affiliates. * * Licensed under the Apache License Version 2.0 with LLVM Exceptions * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://llvm.org/LICENSE.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace unifex { namespace _never { template struct _op { struct type; }; template using operation = typename _op>::type; template struct _op::type { struct cancel_callback { type& op_; void operator()() noexcept { op_.stopCallback_.destruct(); unifex::set_done(static_cast(op_.receiver_)); } }; using stop_token_type = stop_token_type_t; static_assert( !is_stop_never_possible_v, "never should not be used with a stop-token " "type that can never be stopped."); UNIFEX_NO_UNIQUE_ADDRESS Receiver receiver_; manual_lifetime< typename stop_token_type:: template callback_type> stopCallback_; template(typename Receiver2) (requires constructible_from) type(Receiver2&& receiver) : receiver_((Receiver2 &&) receiver) {} void start() noexcept { UNIFEX_ASSERT(get_stop_token(receiver_).stop_possible()); stopCallback_.construct( get_stop_token(receiver_), cancel_callback{*this}); } }; struct sender { template < template class Variant, template class Tuple> using value_types = Variant<>; template