summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tdactor/example/example.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
committeraunsane <aunsane@gmail.com>2018-04-27 21:33:17 +0300
commite1ec72eab6d00b3ba38e5932bc88920f103b6e4a (patch)
tree999de2725a83e30fbbf6576200525d4ef0c5fe38 /protocols/Telegram/tdlib/td/tdactor/example/example.cpp
parentb9ce1d4d98525490ca1a38e2d9fd4f3369adb3e0 (diff)
Telegram: initial commit
- tdlib moved to telegram dir
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdactor/example/example.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/tdactor/example/example.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/tdactor/example/example.cpp b/protocols/Telegram/tdlib/td/tdactor/example/example.cpp
new file mode 100644
index 0000000000..4c2415c5e2
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/tdactor/example/example.cpp
@@ -0,0 +1,49 @@
+//
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+//
+// 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;
+}