diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-04 08:55:10 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-04 08:55:10 +0100 |
| commit | 4b2b47d6edc8c8dd75f260fed3286f5dc4fe9374 (patch) | |
| tree | a4b19757f1db8646a7e80eee9471c008d5d81b07 /example/asio_example/example.cpp | |
| parent | afda75faa95d7c52d73acb9fbf615831cb6dee1a (diff) | |
feat: core: add ASIO example and new IOC helper 'run_loop'.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'example/asio_example/example.cpp')
| -rw-r--r-- | example/asio_example/example.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/example/asio_example/example.cpp b/example/asio_example/example.cpp new file mode 100644 index 0000000..0aeb285 --- /dev/null +++ b/example/asio_example/example.cpp @@ -0,0 +1,33 @@ +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// Official repository: https://git.ocl.nekernel.org/core + +#include <ocl/print.hpp> +#include <ocl/asio.hpp> +#include <ocl/allocator_op.hpp> +#include <future> + +constexpr long int operator ""_USD(long double n) +{ + return n * 1000.0; +} + +/// @brief Wrap OCL in ASIO calls. +int main() +{ + boost::asio::io_context ioc{1}; + auto spawn_strand = boost::asio::make_strand(ioc); + + boost::asio::co_spawn(spawn_strand, [&]() -> boost::asio::awaitable<void> { + ocl::allocator<int> int_alloc; + auto balance = int_alloc.construct_array<1>(); + + *balance = operator ""_USD(150); + ocl::io::println("USD: ", *balance); + co_return; + }, boost::asio::detached); + + ocl::asio::run_loop<[]() { std::terminate(); return; }>(ioc); + return EXIT_SUCCESS; +} |
