//------------------------------------------------------------------------------ /* This file is part of clio: https://github.com/XRPLF/clio Copyright (c) 2024, the clio developers. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #pragma once #include #include #include #include namespace util::async { template concept SomeStoppable = requires(T v) { { v.requestStop() } -> std::same_as; }; template concept SomeCancellable = requires(T v) { { v.cancel() } -> std::same_as; }; template concept SomeOperation = requires(T v) { { v.wait() } -> std::same_as; { v.get() }; }; template concept SomeStoppableOperation = SomeOperation and SomeStoppable; template concept SomeCancellableOperation = SomeOperation and SomeCancellable; template concept SomeOutcome = requires(T v) { { v.getOperation() } -> SomeOperation; }; template concept SomeStopToken = requires(T v) { { v.isStopRequested() } -> std::same_as; }; template concept SomeYieldStopSource = requires(T v, boost::asio::yield_context yield) { { v[yield] } -> SomeStopToken; }; template concept SomeSimpleStopSource = requires(T v) { { v.getToken() } -> SomeStopToken; }; template concept SomeStopSource = (SomeSimpleStopSource or SomeYieldStopSource)and SomeStoppable; template concept SomeStopSourceProvider = requires(T v) { { v.getStopSource() } -> SomeStopSource; }; template concept SomeStoppableOutcome = SomeOutcome and SomeStopSourceProvider; template concept SomeHandlerWithoutStopToken = requires(T fn) { { std::invoke(fn) }; }; template concept SomeHandlerWith = requires(T fn) { { std::invoke(fn, std::declval()...) }; }; template concept SomeStdDuration = requires { // Thank you Ed Catmur for this trick. // See https://stackoverflow.com/questions/74383254/concept-that-models-only-the-stdchrono-duration-types []( // std::type_identity> ) {}(std::type_identity()); }; template concept SomeOptStdDuration = requires(T v) { SomeStdDuration; }; } // namespace util::async