Use free-standing function to create event promises.
This commit is contained in:
parent
aa97336963
commit
513da45a8f
@ -364,7 +364,7 @@ void DeviceTokenManager::save_info(int32 token_type) {
|
|||||||
}
|
}
|
||||||
sync_cnt_++;
|
sync_cnt_++;
|
||||||
G()->td_db()->get_binlog_pmc()->force_sync(
|
G()->td_db()->get_binlog_pmc()->force_sync(
|
||||||
PromiseCreator::event(self_closure(this, &DeviceTokenManager::dec_sync_cnt)));
|
create_event_promise(self_closure(this, &DeviceTokenManager::dec_sync_cnt)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceTokenManager::dec_sync_cnt() {
|
void DeviceTokenManager::dec_sync_cnt() {
|
||||||
|
@ -128,7 +128,7 @@ void StateManager::on_network_soft() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StateManager::start_up() {
|
void StateManager::start_up() {
|
||||||
create_actor<SleepActor>("SleepActor", 1, PromiseCreator::event(self_closure(this, &StateManager::on_network_soft)))
|
create_actor<SleepActor>("SleepActor", 1, create_event_promise(self_closure(this, &StateManager::on_network_soft)))
|
||||||
.release();
|
.release();
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ void TopDialogManager::try_start() {
|
|||||||
db_sync_state_ = SyncState::Ok;
|
db_sync_state_ = SyncState::Ok;
|
||||||
|
|
||||||
send_closure(G()->state_manager(), &StateManager::wait_first_sync,
|
send_closure(G()->state_manager(), &StateManager::wait_first_sync,
|
||||||
PromiseCreator::event(self_closure(this, &TopDialogManager::on_first_sync)));
|
create_event_promise(self_closure(this, &TopDialogManager::on_first_sync)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopDialogManager::on_first_sync() {
|
void TopDialogManager::on_first_sync() {
|
||||||
|
@ -372,12 +372,12 @@ void UpdatesManager::before_get_difference(bool is_initial) {
|
|||||||
|
|
||||||
Promise<> UpdatesManager::add_pts(int32 pts) {
|
Promise<> UpdatesManager::add_pts(int32 pts) {
|
||||||
auto id = pts_manager_.add_pts(pts);
|
auto id = pts_manager_.add_pts(pts);
|
||||||
return PromiseCreator::event(self_closure(this, &UpdatesManager::on_pts_ack, id));
|
return create_event_promise(self_closure(this, &UpdatesManager::on_pts_ack, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise<> UpdatesManager::add_qts(int32 qts) {
|
Promise<> UpdatesManager::add_qts(int32 qts) {
|
||||||
auto id = qts_manager_.add_pts(qts);
|
auto id = qts_manager_.add_pts(qts);
|
||||||
return PromiseCreator::event(self_closure(this, &UpdatesManager::on_qts_ack, id));
|
return create_event_promise(self_closure(this, &UpdatesManager::on_qts_ack, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatesManager::on_pts_ack(PtsManager::PtsId ack_token) {
|
void UpdatesManager::on_pts_ack(PtsManager::PtsId ack_token) {
|
||||||
|
@ -399,6 +399,14 @@ class JoinPromise final : public PromiseInterface<Unit> {
|
|||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
inline Promise<Unit> create_event_promise(EventFull &&ok) {
|
||||||
|
return Promise<Unit>(td::make_unique<detail::EventPromise>(std::move(ok)));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Promise<Unit> create_event_promise(EventFull ok, EventFull fail) {
|
||||||
|
return Promise<Unit>(td::make_unique<detail::EventPromise>(std::move(ok), std::move(fail)));
|
||||||
|
}
|
||||||
|
|
||||||
class SendClosure {
|
class SendClosure {
|
||||||
public:
|
public:
|
||||||
template <class... ArgsT>
|
template <class... ArgsT>
|
||||||
@ -663,14 +671,6 @@ class PromiseCreator {
|
|||||||
std::move(cancellation_token), std::forward<OkT>(ok)));
|
std::move(cancellation_token), std::forward<OkT>(ok)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Promise<> event(EventFull &&ok) {
|
|
||||||
return Promise<>(td::make_unique<detail::EventPromise>(std::move(ok)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static Promise<> event(EventFull ok, EventFull fail) {
|
|
||||||
return Promise<>(td::make_unique<detail::EventPromise>(std::move(ok), std::move(fail)));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... ArgsT>
|
template <class... ArgsT>
|
||||||
static Promise<> join(ArgsT &&...args) {
|
static Promise<> join(ArgsT &&...args) {
|
||||||
return Promise<>(td::make_unique<detail::JoinPromise<ArgsT...>>(std::forward<ArgsT>(args)...));
|
return Promise<>(td::make_unique<detail::JoinPromise<ArgsT...>>(std::forward<ArgsT>(args)...));
|
||||||
|
@ -691,12 +691,12 @@ class LoginTestActor final : public td::Actor {
|
|||||||
td::send_closure(alice_, &TestClient::add_listener,
|
td::send_closure(alice_, &TestClient::add_listener,
|
||||||
td::make_unique<DoAuthentication>(
|
td::make_unique<DoAuthentication>(
|
||||||
"alice", alice_phone_, "33333",
|
"alice", alice_phone_, "33333",
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::start_up_fence_dec))));
|
td::create_event_promise(self_closure(this, &LoginTestActor::start_up_fence_dec))));
|
||||||
|
|
||||||
td::send_closure(bob_, &TestClient::add_listener,
|
td::send_closure(bob_, &TestClient::add_listener,
|
||||||
td::make_unique<DoAuthentication>(
|
td::make_unique<DoAuthentication>(
|
||||||
"bob", bob_phone_, "33333",
|
"bob", bob_phone_, "33333",
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::start_up_fence_dec))));
|
td::create_event_promise(self_closure(this, &LoginTestActor::start_up_fence_dec))));
|
||||||
}
|
}
|
||||||
|
|
||||||
int start_up_fence_ = 3;
|
int start_up_fence_ = 3;
|
||||||
@ -722,18 +722,18 @@ class LoginTestActor final : public td::Actor {
|
|||||||
td::Promise<> promise_;
|
td::Promise<> promise_;
|
||||||
};
|
};
|
||||||
td::create_actor<WaitActor>("WaitActor", 2,
|
td::create_actor<WaitActor>("WaitActor", 2,
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::start_up_fence_dec)))
|
td::create_event_promise(self_closure(this, &LoginTestActor::start_up_fence_dec)))
|
||||||
.release();
|
.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
td::send_closure(alice_, &TestClient::add_listener,
|
td::send_closure(alice_, &TestClient::add_listener,
|
||||||
td::make_unique<SetUsername>(alice_username_, td::PromiseCreator::event(self_closure(
|
td::make_unique<SetUsername>(alice_username_, td::create_event_promise(self_closure(
|
||||||
this, &LoginTestActor::init_fence_dec))));
|
this, &LoginTestActor::init_fence_dec))));
|
||||||
td::send_closure(bob_, &TestClient::add_listener,
|
td::send_closure(bob_, &TestClient::add_listener,
|
||||||
td::make_unique<SetUsername>(bob_username_, td::PromiseCreator::event(self_closure(
|
td::make_unique<SetUsername>(
|
||||||
this, &LoginTestActor::init_fence_dec))));
|
bob_username_, td::create_event_promise(self_closure(this, &LoginTestActor::init_fence_dec))));
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_fence_ = 2;
|
int init_fence_ = 2;
|
||||||
@ -757,10 +757,10 @@ class LoginTestActor final : public td::Actor {
|
|||||||
|
|
||||||
td::send_closure(bob_, &TestClient::add_listener,
|
td::send_closure(bob_, &TestClient::add_listener,
|
||||||
td::make_unique<CheckTestA>(
|
td::make_unique<CheckTestA>(
|
||||||
alice_tag, td::PromiseCreator::event(self_closure(this, &LoginTestActor::test_a_fence))));
|
alice_tag, td::create_event_promise(self_closure(this, &LoginTestActor::test_a_fence))));
|
||||||
td::send_closure(alice_, &TestClient::add_listener,
|
td::send_closure(alice_, &TestClient::add_listener,
|
||||||
td::make_unique<CheckTestA>(
|
td::make_unique<CheckTestA>(
|
||||||
bob_tag, td::PromiseCreator::event(self_closure(this, &LoginTestActor::test_a_fence))));
|
bob_tag, td::create_event_promise(self_closure(this, &LoginTestActor::test_a_fence))));
|
||||||
|
|
||||||
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestA>(alice_tag, bob_username_));
|
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestA>(alice_tag, bob_username_));
|
||||||
td::send_closure(bob_, &TestClient::add_listener, td::make_unique<TestA>(bob_tag, alice_username_));
|
td::send_closure(bob_, &TestClient::add_listener, td::make_unique<TestA>(bob_tag, alice_username_));
|
||||||
@ -791,7 +791,7 @@ class LoginTestActor final : public td::Actor {
|
|||||||
|
|
||||||
td::send_closure(
|
td::send_closure(
|
||||||
bob_, &TestClient::add_listener,
|
bob_, &TestClient::add_listener,
|
||||||
td::make_unique<CheckTestA>(tag, td::PromiseCreator::event(self_closure(this, &LoginTestActor::test_b_fence))));
|
td::make_unique<CheckTestA>(tag, td::create_event_promise(self_closure(this, &LoginTestActor::test_b_fence))));
|
||||||
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestSecretChat>(tag, bob_username_));
|
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestSecretChat>(tag, bob_username_));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -802,7 +802,7 @@ class LoginTestActor final : public td::Actor {
|
|||||||
td::send_closure(
|
td::send_closure(
|
||||||
bob_, &TestClient::add_listener,
|
bob_, &TestClient::add_listener,
|
||||||
td::make_unique<CheckTestC>(alice_username_, tag,
|
td::make_unique<CheckTestC>(alice_username_, tag,
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::test_c_fence))));
|
td::create_event_promise(self_closure(this, &LoginTestActor::test_c_fence))));
|
||||||
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestFileGenerated>(tag, bob_username_));
|
td::send_closure(alice_, &TestClient::add_listener, td::make_unique<TestFileGenerated>(tag, bob_username_));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -817,9 +817,9 @@ class LoginTestActor final : public td::Actor {
|
|||||||
|
|
||||||
void finish() {
|
void finish() {
|
||||||
td::send_closure(alice_, &TestClient::close,
|
td::send_closure(alice_, &TestClient::close,
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::finish_fence)));
|
td::create_event_promise(self_closure(this, &LoginTestActor::finish_fence)));
|
||||||
td::send_closure(bob_, &TestClient::close,
|
td::send_closure(bob_, &TestClient::close,
|
||||||
td::PromiseCreator::event(self_closure(this, &LoginTestActor::finish_fence)));
|
td::create_event_promise(self_closure(this, &LoginTestActor::finish_fence)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user