summaryrefslogtreecommitdiffhomepage
path: root/example/asio_example/example.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-09 05:56:55 +0100
committerGitHub <noreply@github.com>2026-03-09 05:56:55 +0100
commit61f30bafcd2d696f1f58ca1a1848e10f80fe8298 (patch)
tree1a40be421bf982e6dc3b6f1e569f8c617d9ca760 /example/asio_example/example.cpp
parentb960d11ea2fca1d0a4babc61aadfc14b94f8e09b (diff)
parentd363f0dc2325a1811b009ec0f96952f66ce100e9 (diff)
Merge pull request #5 from ocl-foss-org/new-examples-asio
[CHORE] Add new TProc example.
Diffstat (limited to 'example/asio_example/example.cpp')
-rw-r--r--example/asio_example/example.cpp39
1 files changed, 39 insertions, 0 deletions
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;
+}