2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
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"
|
2020-11-23 01:24:36 +01:00
|
|
|
#include "td/actor/ConcurrentScheduler.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class Worker final : public td::Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
void ping(int x) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(ERROR) << "Got ping " << x;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MainActor final : public td::Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(ERROR) << "Start up";
|
2018-12-31 20:04:05 +01:00
|
|
|
set_timeout_in(10);
|
|
|
|
worker_ = td::create_actor_on_scheduler<Worker>("Worker", 1);
|
|
|
|
send_closure(worker_, &Worker::ping, 123);
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void timeout_expired() final {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(ERROR) << "Timeout expired";
|
2018-12-31 20:04:05 +01:00
|
|
|
td::Scheduler::instance()->finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
td::ActorOwn<Worker> worker_;
|
|
|
|
};
|
|
|
|
|
2021-10-21 11:51:16 +02:00
|
|
|
int main() {
|
2022-09-14 14:06:52 +02:00
|
|
|
td::ConcurrentScheduler scheduler(4 /*thread_count*/, 0);
|
2018-12-31 20:04:05 +01:00
|
|
|
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();
|
|
|
|
}
|