summaryrefslogtreecommitdiffhomepage
path: root/example/asio_example
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-09 05:55:14 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-09 05:55:14 +0100
commitd363f0dc2325a1811b009ec0f96952f66ce100e9 (patch)
tree1a40be421bf982e6dc3b6f1e569f8c617d9ca760 /example/asio_example
parentc04caf00cb62aaecaaa930b622a06af4b1d7e92b (diff)
[CHORE] Add new TProc example.new-examples-asio
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'example/asio_example')
-rw-r--r--example/asio_example/Jamfile.v214
-rw-r--r--example/asio_example/example.cpp39
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;
+}