diff options
Diffstat (limited to 'example')
| -rw-r--r-- | example/asio_example/Jamfile.v2 | 14 | ||||
| -rw-r--r-- | example/asio_example/example.cpp | 39 |
2 files changed, 53 insertions, 0 deletions
diff --git a/example/asio_example/Jamfile.v2 b/example/asio_example/Jamfile.v2 new file mode 100644 index 0000000..4bfc827 --- /dev/null +++ b/example/asio_example/Jamfile.v2 @@ -0,0 +1,14 @@ +# +# File: Jamfile.v2 +# Author: Amlal El Mahrouss, +# Copyright 2026, Amlal El Mahrouss, Licensed under the Boost Software License +# + +project tests +: default-build debug +; + +exe example.o + : example.cpp + : <cxxstd>20 ; + diff --git a/example/asio_example/example.cpp b/example/asio_example/example.cpp new file mode 100644 index 0000000..5ba520d --- /dev/null +++ b/example/asio_example/example.cpp @@ -0,0 +1,39 @@ +/* + * File: example.cpp + * Purpose: Rope example. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025-2026, Amlal El Mahrouss, licensed under the Boost Software License. + */ + +#include <ocl/tproc/rope.hpp> +#include <ocl/asio.hpp> +#include <iostream> +#include <memory> +#include <future> + +#ifndef STANDALONE +using namespace ocl; +#else +using namespace boost; +#endif + +int main() +{ + auto rope = tproc::crope("The Quick Brown Fox Jumps Over The Lazy Dog"); + auto new_elem = std::make_unique<tproc::crope>(", and Jumps again"); + auto new_elem_2 = std::make_unique<tproc::crope>(", and then Jumps down."); + + boost::asio::io_context ioc{1}; + auto spawn_strand = boost::asio::make_strand(ioc); + + boost::asio::co_spawn(spawn_strand, [&new_elem, &new_elem_2, &rope]() -> boost::asio::awaitable<void> { + rope.concat(new_elem.get()); + new_elem->concat(new_elem_2.get()); + + co_return; + }, boost::asio::detached); + + ocl::asio::run<[]() { (void)0; }>(ioc); + + std::cout << rope << std::endl; +} |
