2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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"
|
2018-09-27 15:37:15 +02:00
|
|
|
#include "td/utils/Time.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
{
|
2018-09-18 15:43:16 +02:00
|
|
|
auto guard = scheduler.get_main_guard();
|
2018-12-31 20:04:05 +01:00
|
|
|
td::create_actor_on_scheduler<MainActor>("Main actor", 0).release();
|
|
|
|
}
|
|
|
|
while (!scheduler.is_finished()) {
|
2018-09-18 15:43:16 +02:00
|
|
|
scheduler.run_main(td::Timestamp::in(10));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
scheduler.finish();
|
|
|
|
return 0;
|
|
|
|
}
|