aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdactor/example
diff options
context:
space:
mode:
authorArseny Smirnov <arseny30@gmail.com>2018-12-31 22:04:05 +0300
committerArseny Smirnov <arseny30@gmail.com>2017-12-31 23:08:40 +0300
commit71d03f39c364367a8a7c51f783a41099297de826 (patch)
tree4c0c57f9ddb87f46d58192e1ebfd2c40f6d2c315 /tdactor/example
Project import generated by Copybara.
GitOrigin-RevId: 318483224ad6164d9966f731d60cde37039bb2d4
Diffstat (limited to 'tdactor/example')
-rw-r--r--tdactor/example/example.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tdactor/example/example.cpp b/tdactor/example/example.cpp
new file mode 100644
index 000000000..326da6803
--- /dev/null
+++ b/tdactor/example/example.cpp
@@ -0,0 +1,49 @@
+//
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2017
+//
+// 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)
+//
+#include "td/actor/actor.h"
+
+#include "td/utils/logging.h"
+
+class Worker : public td::Actor {
+ public:
+ void ping(int x) {
+ LOG(ERROR) << "got ping " << x;
+ }
+};
+
+class MainActor : public td::Actor {
+ public:
+ void start_up() override {
+ LOG(ERROR) << "start up";
+ set_timeout_in(10);
+ worker_ = td::create_actor_on_scheduler<Worker>("Worker", 1);
+ send_closure(worker_, &Worker::ping, 123);
+ }
+
+ void timeout_expired() override {
+ LOG(ERROR) << "timeout expired";
+ td::Scheduler::instance()->finish();
+ }
+
+ private:
+ td::ActorOwn<Worker> worker_;
+};
+
+int main(void) {
+ td::ConcurrentScheduler scheduler;
+ scheduler.init(4 /*threads_count*/);
+ scheduler.start();
+ {
+ auto guard = scheduler.get_current_guard();
+ td::create_actor_on_scheduler<MainActor>("Main actor", 0).release();
+ }
+ while (!scheduler.is_finished()) {
+ scheduler.run_main(10);
+ }
+ scheduler.finish();
+ return 0;
+}