diff options
116 files changed, 502 insertions, 524 deletions
diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index 66f2e72e3..f68a8d8e0 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -12,6 +12,7 @@ #include "td/utils/common.h" #include "td/utils/crypto.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/SliceBuilder.h" #if TD_MSVC diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index f62c5cd66..eb6880359 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -16,12 +16,12 @@ #include "td/db/SqliteDb.h" #include "td/actor/ConcurrentScheduler.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/benchmark.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Random.h" #include "td/utils/Status.h" diff --git a/benchmark/wget.cpp b/benchmark/wget.cpp index 31bedc861..1fdfc2af1 100644 --- a/benchmark/wget.cpp +++ b/benchmark/wget.cpp @@ -9,10 +9,10 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" int main(int argc, char *argv[]) { diff --git a/td/mtproto/HandshakeActor.h b/td/mtproto/HandshakeActor.h index 3463bbb2b..cab4ae54c 100644 --- a/td/mtproto/HandshakeActor.h +++ b/td/mtproto/HandshakeActor.h @@ -11,8 +11,8 @@ #include "td/mtproto/RawConnection.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/mtproto/Ping.cpp b/td/mtproto/Ping.cpp index d9b580459..c8e2a1a6c 100644 --- a/td/mtproto/Ping.cpp +++ b/td/mtproto/Ping.cpp @@ -10,9 +10,6 @@ #include "td/mtproto/PingConnection.h" #include "td/mtproto/RawConnection.h" -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" diff --git a/td/mtproto/Ping.h b/td/mtproto/Ping.h index f3d8d8cf0..09bc35610 100644 --- a/td/mtproto/Ping.h +++ b/td/mtproto/Ping.h @@ -10,9 +10,9 @@ #include "td/mtproto/RawConnection.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" namespace td { diff --git a/td/telegram/Account.h b/td/telegram/Account.h index 3864c8416..cca9d9f37 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -9,9 +9,8 @@ #include "td/telegram/DialogParticipant.h" #include "td/telegram/td_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 454da8151..b645b8b5b 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -27,8 +27,6 @@ #include "td/db/SqliteKeyValueAsync.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/algorithm.h" #include "td/utils/logging.h" #include "td/utils/misc.h" diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index c3f821b11..17c5f9559 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -15,11 +15,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/Application.h b/td/telegram/Application.h index b0d18cbd2..4ca4ca7ac 100644 --- a/td/telegram/Application.h +++ b/td/telegram/Application.h @@ -9,9 +9,8 @@ #include "td/telegram/DialogId.h" #include "td/telegram/telegram_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/AttachMenuManager.h b/td/telegram/AttachMenuManager.h index 8bc10e2fd..5ec2d4d54 100644 --- a/td/telegram/AttachMenuManager.h +++ b/td/telegram/AttachMenuManager.h @@ -14,11 +14,11 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 861afc1ec..97a1a2694 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -28,12 +28,11 @@ #include "td/telegram/TopDialogManager.h" #include "td/telegram/UpdatesManager.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/base64.h" #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/Promise.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" #include "td/utils/Time.h" diff --git a/td/telegram/AutoDownloadSettings.h b/td/telegram/AutoDownloadSettings.h index 9efce1ffe..c77185829 100644 --- a/td/telegram/AutoDownloadSettings.h +++ b/td/telegram/AutoDownloadSettings.h @@ -9,9 +9,8 @@ #include "td/telegram/net/NetType.h" #include "td/telegram/td_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index ab360e8bc..996e00442 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -15,11 +15,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <memory> diff --git a/td/telegram/BotCommand.h b/td/telegram/BotCommand.h index 956217792..23d683b11 100644 --- a/td/telegram/BotCommand.h +++ b/td/telegram/BotCommand.h @@ -10,9 +10,8 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/BotMenuButton.h b/td/telegram/BotMenuButton.h index a9069b2c0..79f4b5464 100644 --- a/td/telegram/BotMenuButton.h +++ b/td/telegram/BotMenuButton.h @@ -10,9 +10,8 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/CallActor.h b/td/telegram/CallActor.h index 97186f35f..cb674ac55 100644 --- a/td/telegram/CallActor.h +++ b/td/telegram/CallActor.h @@ -18,10 +18,10 @@ #include "td/mtproto/DhHandshake.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Container.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <memory> diff --git a/td/telegram/CallManager.h b/td/telegram/CallManager.h index 54a16f32b..3d0f82a84 100644 --- a/td/telegram/CallManager.h +++ b/td/telegram/CallManager.h @@ -12,10 +12,10 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <map> diff --git a/td/telegram/CallbackQueriesManager.cpp b/td/telegram/CallbackQueriesManager.cpp index 872bdeffb..d9bdb6b11 100644 --- a/td/telegram/CallbackQueriesManager.cpp +++ b/td/telegram/CallbackQueriesManager.cpp @@ -18,7 +18,6 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/logging.h" diff --git a/td/telegram/CallbackQueriesManager.h b/td/telegram/CallbackQueriesManager.h index c3eb1ea4a..e59e1b778 100644 --- a/td/telegram/CallbackQueriesManager.h +++ b/td/telegram/CallbackQueriesManager.h @@ -13,10 +13,9 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index b04be2133..272058c5f 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -14,11 +14,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FloodControlStrict.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5b1e27431..9b217baee 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -55,7 +55,6 @@ #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueAsync.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" #include "td/utils/algorithm.h" diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 36b8f75a8..d7669f729 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -39,13 +39,13 @@ #include "td/actor/actor.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" #include "td/utils/Hints.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/td/telegram/CountryInfoManager.h b/td/telegram/CountryInfoManager.h index 270caebad..013c5024e 100644 --- a/td/telegram/CountryInfoManager.h +++ b/td/telegram/CountryInfoManager.h @@ -10,10 +10,10 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/DeviceTokenManager.cpp b/td/telegram/DeviceTokenManager.cpp index d7d935d61..727e0bc23 100644 --- a/td/telegram/DeviceTokenManager.cpp +++ b/td/telegram/DeviceTokenManager.cpp @@ -16,6 +16,8 @@ #include "td/mtproto/DhHandshake.h" +#include "td/actor/PromiseFuture.h" + #include "td/utils/algorithm.h" #include "td/utils/base64.h" #include "td/utils/buffer.h" diff --git a/td/telegram/DeviceTokenManager.h b/td/telegram/DeviceTokenManager.h index 2a03ba259..faf13ef11 100644 --- a/td/telegram/DeviceTokenManager.h +++ b/td/telegram/DeviceTokenManager.h @@ -11,9 +11,9 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/DialogDb.h b/td/telegram/DialogDb.h index 08a4f5111..9a9dfec66 100644 --- a/td/telegram/DialogDb.h +++ b/td/telegram/DialogDb.h @@ -13,10 +13,9 @@ #include "td/db/KeyValueSyncInterface.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <memory> diff --git a/td/telegram/DialogEventLog.h b/td/telegram/DialogEventLog.h index 2d88d5e4a..e47af602f 100644 --- a/td/telegram/DialogEventLog.h +++ b/td/telegram/DialogEventLog.h @@ -10,9 +10,8 @@ #include "td/telegram/td_api.h" #include "td/telegram/UserId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/DownloadManager.h b/td/telegram/DownloadManager.h index 1b3ba51be..aa0790fd9 100644 --- a/td/telegram/DownloadManager.h +++ b/td/telegram/DownloadManager.h @@ -12,9 +12,9 @@ #include "td/telegram/td_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/DownloadManagerCallback.cpp b/td/telegram/DownloadManagerCallback.cpp index 9233a7f82..c938756c3 100644 --- a/td/telegram/DownloadManagerCallback.cpp +++ b/td/telegram/DownloadManagerCallback.cpp @@ -11,9 +11,9 @@ #include "td/telegram/Td.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index 986fe0212..340040db6 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -18,11 +18,11 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Variant.h" diff --git a/td/telegram/GameManager.h b/td/telegram/GameManager.h index 1933f3079..084a664ec 100644 --- a/td/telegram/GameManager.h +++ b/td/telegram/GameManager.h @@ -12,9 +12,9 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 5a388fa92..e8df3c801 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -14,8 +14,6 @@ #include "td/telegram/StateManager.h" #include "td/telegram/TdDb.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" diff --git a/td/telegram/Global.h b/td/telegram/Global.h index ae2f6a171..cda08328f 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -15,12 +15,12 @@ #include "td/net/NetStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SchedulerLocalStorage.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 894a600ca..fe5af5761 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -17,11 +17,11 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/td/telegram/HashtagHints.h b/td/telegram/HashtagHints.h index ea51470d4..9434769fa 100644 --- a/td/telegram/HashtagHints.h +++ b/td/telegram/HashtagHints.h @@ -7,10 +7,10 @@ #pragma once #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Hints.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/InlineQueriesManager.h b/td/telegram/InlineQueriesManager.h index 8c3effa6d..ab7365587 100644 --- a/td/telegram/InlineQueriesManager.h +++ b/td/telegram/InlineQueriesManager.h @@ -19,11 +19,11 @@ #include "td/actor/actor.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/td/telegram/LanguagePackManager.h b/td/telegram/LanguagePackManager.h index 754b41124..973d8d3b1 100644 --- a/td/telegram/LanguagePackManager.h +++ b/td/telegram/LanguagePackManager.h @@ -11,11 +11,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Container.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index 38d675ac5..2fe6183c4 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -12,9 +12,9 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index c0d9fbe8a..68ea785a4 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -76,7 +76,6 @@ #include "td/actor/actor.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/algorithm.h" #include "td/utils/emoji.h" diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 9a65153ea..5ce9af19e 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -26,10 +26,9 @@ #include "td/telegram/UserId.h" #include "td/telegram/WebPageId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index a2ce9e918..bdb098845 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -14,10 +14,9 @@ #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/StringBuilder.h" #include <utility> diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 187a1e7ba..87a819201 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -14,7 +14,6 @@ #include "td/db/SqliteStatement.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SchedulerLocalStorage.h" #include "td/utils/format.h" diff --git a/td/telegram/MessagesDb.h b/td/telegram/MessagesDb.h index 3ac11b35d..94ab7cba5 100644 --- a/td/telegram/MessagesDb.h +++ b/td/telegram/MessagesDb.h @@ -13,10 +13,9 @@ #include "td/telegram/NotificationId.h" #include "td/telegram/ServerMessageId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <memory> diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4a691047b..9dbb6f466 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -68,7 +68,6 @@ #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueAsync.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" #include "td/utils/algorithm.h" diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 004953d53..9a0f630a3 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -61,7 +61,6 @@ #include "td/actor/actor.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" #include "td/actor/Timeout.h" @@ -73,6 +72,7 @@ #include "td/utils/Heap.h" #include "td/utils/Hints.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 69a3ddb6c..492063e51 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -21,13 +21,13 @@ #include "td/telegram/td_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/td/telegram/NotificationSettingsManager.h b/td/telegram/NotificationSettingsManager.h index c88be9458..6e55591ea 100644 --- a/td/telegram/NotificationSettingsManager.h +++ b/td/telegram/NotificationSettingsManager.h @@ -14,11 +14,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <memory> diff --git a/td/telegram/OptionManager.h b/td/telegram/OptionManager.h index d6c1e7e20..2bfd1d341 100644 --- a/td/telegram/OptionManager.h +++ b/td/telegram/OptionManager.h @@ -9,9 +9,9 @@ #include "td/telegram/td_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" namespace td { diff --git a/td/telegram/PasswordManager.h b/td/telegram/PasswordManager.h index ada95a267..dd5eb1546 100644 --- a/td/telegram/PasswordManager.h +++ b/td/telegram/PasswordManager.h @@ -13,12 +13,12 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/Container.h" #include "td/utils/optional.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/Payments.h b/td/telegram/Payments.h index 13deb0e31..f6896645e 100644 --- a/td/telegram/Payments.h +++ b/td/telegram/Payments.h @@ -14,9 +14,8 @@ #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index 59f3e0a03..90a0a8802 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -16,13 +16,13 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/td/telegram/Premium.h b/td/telegram/Premium.h index 9e5dfa9f2..fa97a471d 100644 --- a/td/telegram/Premium.h +++ b/td/telegram/Premium.h @@ -8,9 +8,8 @@ #include "td/telegram/td_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" namespace td { diff --git a/td/telegram/PrivacyManager.h b/td/telegram/PrivacyManager.h index 789d01e44..2632f5ff7 100644 --- a/td/telegram/PrivacyManager.h +++ b/td/telegram/PrivacyManager.h @@ -12,10 +12,10 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Container.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <array> diff --git a/td/telegram/QueryCombiner.h b/td/telegram/QueryCombiner.h index ae9b1c99a..7d1542715 100644 --- a/td/telegram/QueryCombiner.h +++ b/td/telegram/QueryCombiner.h @@ -7,10 +7,10 @@ #pragma once #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/RecentDialogList.h b/td/telegram/RecentDialogList.h index b12edb8a6..1163c73aa 100644 --- a/td/telegram/RecentDialogList.h +++ b/td/telegram/RecentDialogList.h @@ -9,10 +9,10 @@ #include "td/telegram/DialogId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/FlatHashSet.h" +#include "td/utils/Promise.h" #include <utility> diff --git a/td/telegram/RequestActor.h b/td/telegram/RequestActor.h index 03827c04b..3463e2994 100644 --- a/td/telegram/RequestActor.h +++ b/td/telegram/RequestActor.h @@ -15,6 +15,7 @@ #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <type_traits> @@ -37,7 +38,7 @@ class RequestActor : public Actor { FutureActor<T> future; init_promise_future(&promise_actor, &future); - auto promise = PromiseCreator::from_promise_actor(std::move(promise_actor)); + auto promise = create_promise_from_promise_actor(std::move(promise_actor)); do_run(std::move(promise)); if (future.is_ready()) { diff --git a/td/telegram/SecretChatActor.h b/td/telegram/SecretChatActor.h index 775e3d1c7..afae8dc6d 100644 --- a/td/telegram/SecretChatActor.h +++ b/td/telegram/SecretChatActor.h @@ -24,7 +24,6 @@ #include "td/mtproto/DhHandshake.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/ChangesProcessor.h" @@ -32,6 +31,7 @@ #include "td/utils/Container.h" #include "td/utils/format.h" #include "td/utils/port/Clocks.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 2a8a50c91..696e4bd68 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -28,8 +28,6 @@ #include "td/db/binlog/BinlogHelper.h" #include "td/db/binlog/BinlogInterface.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" #include "td/utils/format.h" #include "td/utils/logging.h" diff --git a/td/telegram/SecretChatsManager.h b/td/telegram/SecretChatsManager.h index 1e2ca83c3..cacd5263c 100644 --- a/td/telegram/SecretChatsManager.h +++ b/td/telegram/SecretChatsManager.h @@ -14,9 +14,9 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Time.h" #include <map> diff --git a/td/telegram/SecureManager.h b/td/telegram/SecureManager.h index e4180254b..c895f4381 100644 --- a/td/telegram/SecureManager.h +++ b/td/telegram/SecureManager.h @@ -14,11 +14,11 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" #include "td/utils/Container.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <map> diff --git a/td/telegram/SequenceDispatcher.cpp b/td/telegram/SequenceDispatcher.cpp index 7fa0c27a6..fb01bdb94 100644 --- a/td/telegram/SequenceDispatcher.cpp +++ b/td/telegram/SequenceDispatcher.cpp @@ -10,13 +10,12 @@ #include "td/telegram/net/NetQueryDispatcher.h" #include "td/telegram/Td.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/algorithm.h" #include "td/utils/ChainScheduler.h" #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/Promise.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/SponsoredMessageManager.h b/td/telegram/SponsoredMessageManager.h index a35adecbd..6e11aa04f 100644 --- a/td/telegram/SponsoredMessageManager.h +++ b/td/telegram/SponsoredMessageManager.h @@ -12,11 +12,11 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/StateManager.h b/td/telegram/StateManager.h index 66b0dabcd..b32448f80 100644 --- a/td/telegram/StateManager.h +++ b/td/telegram/StateManager.h @@ -12,9 +12,9 @@ #include "td/mtproto/ConnectionManager.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 6160e1bb4..edefbcc40 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -41,8 +41,6 @@ #include "td/db/SqliteKeyValue.h" #include "td/db/SqliteKeyValueAsync.h" -#include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" #include "td/utils/algorithm.h" diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index eef623515..fb0876b46 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -22,7 +22,6 @@ #include "td/actor/actor.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/buffer.h" @@ -30,6 +29,7 @@ #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" #include "td/utils/Hints.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index 2650ea57f..9c6c39bf8 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -12,10 +12,10 @@ #include "td/telegram/td_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/CancellationToken.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/SuggestedAction.h b/td/telegram/SuggestedAction.h index c64144815..af33f9202 100644 --- a/td/telegram/SuggestedAction.h +++ b/td/telegram/SuggestedAction.h @@ -9,9 +9,8 @@ #include "td/telegram/DialogId.h" #include "td/telegram/td_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" namespace td { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 836d2fbc8..d7686486d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -134,7 +134,6 @@ #include "td/mtproto/TransportType.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/algorithm.h" #include "td/utils/buffer.h" diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 0e4c33ef4..f7323d86a 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -21,7 +21,6 @@ #include "td/db/DbKey.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/buffer.h" @@ -29,6 +28,7 @@ #include "td/utils/Container.h" #include "td/utils/FlatHashMap.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/TdDb.h b/td/telegram/TdDb.h index 957d0d842..db0a732e7 100644 --- a/td/telegram/TdDb.h +++ b/td/telegram/TdDb.h @@ -13,8 +13,7 @@ #include "td/db/DbKey.h" #include "td/db/KeyValueSyncInterface.h" -#include "td/actor/PromiseFuture.h" - +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/TermsOfService.h b/td/telegram/TermsOfService.h index 7ac832fa7..410526da8 100644 --- a/td/telegram/TermsOfService.h +++ b/td/telegram/TermsOfService.h @@ -11,9 +11,8 @@ #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/ThemeManager.h b/td/telegram/ThemeManager.h index ffed0aed4..e11b9038e 100644 --- a/td/telegram/ThemeManager.h +++ b/td/telegram/ThemeManager.h @@ -12,9 +12,9 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index 52aabc622..679b54ede 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -22,6 +22,8 @@ #include "td/telegram/TdDb.h" #include "td/telegram/TdParameters.h" +#include "td/actor/PromiseFuture.h" + #include "td/utils/algorithm.h" #include "td/utils/buffer.h" #include "td/utils/logging.h" diff --git a/td/telegram/TopDialogManager.h b/td/telegram/TopDialogManager.h index 175ec7805..fa5e47a25 100644 --- a/td/telegram/TopDialogManager.h +++ b/td/telegram/TopDialogManager.h @@ -11,9 +11,9 @@ #include "td/telegram/TopDialogCategory.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 0f9279ba1..c020d9482 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -57,6 +57,7 @@ #include "td/telegram/WebPagesManager.h" #include "td/actor/MultiPromise.h" +#include "td/actor/PromiseFuture.h" #include "td/utils/algorithm.h" #include "td/utils/buffer.h" diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index b637bb4a7..1c72b649c 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -17,12 +17,12 @@ #include "td/telegram/UserId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashSet.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/tl_storers.h" #include "td/utils/TlStorerToString.h" diff --git a/td/telegram/VoiceNotesManager.h b/td/telegram/VoiceNotesManager.h index 11138157c..60c0681d5 100644 --- a/td/telegram/VoiceNotesManager.h +++ b/td/telegram/VoiceNotesManager.h @@ -13,12 +13,12 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index cfe447818..95d280407 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -16,12 +16,12 @@ #include "td/telegram/WebPageId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/td/telegram/files/FileDb.h b/td/telegram/files/FileDb.h index 51eeb9ae7..db6a26f5c 100644 --- a/td/telegram/files/FileDb.h +++ b/td/telegram/files/FileDb.h @@ -9,11 +9,10 @@ #include "td/telegram/files/FileData.h" #include "td/telegram/files/FileDbId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/tl_storers.h" diff --git a/td/telegram/files/FileGcWorker.h b/td/telegram/files/FileGcWorker.h index cb5567362..e7da77f18 100644 --- a/td/telegram/files/FileGcWorker.h +++ b/td/telegram/files/FileGcWorker.h @@ -10,10 +10,10 @@ #include "td/telegram/files/FileStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/CancellationToken.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/files/FileGenerateManager.h b/td/telegram/files/FileGenerateManager.h index 22c20f4db..3df9d5e89 100644 --- a/td/telegram/files/FileGenerateManager.h +++ b/td/telegram/files/FileGenerateManager.h @@ -9,8 +9,8 @@ #include "td/telegram/files/FileLocation.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <map> diff --git a/td/telegram/files/FileLoadManager.h b/td/telegram/files/FileLoadManager.h index 95884eca7..9192c0cc2 100644 --- a/td/telegram/files/FileLoadManager.h +++ b/td/telegram/files/FileLoadManager.h @@ -17,11 +17,11 @@ #include "td/telegram/net/DcId.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/Container.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <map> diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 33d62023f..e8bb35992 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -21,7 +21,6 @@ #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" @@ -31,6 +30,7 @@ #include "td/utils/FlatHashSet.h" #include "td/utils/logging.h" #include "td/utils/optional.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/files/FileStatsWorker.h b/td/telegram/files/FileStatsWorker.h index da38d799e..71c4a7003 100644 --- a/td/telegram/files/FileStatsWorker.h +++ b/td/telegram/files/FileStatsWorker.h @@ -9,9 +9,9 @@ #include "td/telegram/files/FileStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/CancellationToken.h" +#include "td/utils/Promise.h" namespace td { diff --git a/td/telegram/logevent/LogEventHelper.h b/td/telegram/logevent/LogEventHelper.h index c9c23d757..b1beb6756 100644 --- a/td/telegram/logevent/LogEventHelper.h +++ b/td/telegram/logevent/LogEventHelper.h @@ -8,9 +8,8 @@ #include "td/telegram/Global.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/StorerBase.h" #include "td/utils/Time.h" diff --git a/td/telegram/logevent/SecretChatEvent.h b/td/telegram/logevent/SecretChatEvent.h index f5951d039..4072eaf6e 100644 --- a/td/telegram/logevent/SecretChatEvent.h +++ b/td/telegram/logevent/SecretChatEvent.h @@ -13,11 +13,10 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/format.h" +#include "td/utils/Promise.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index 16082dd13..92c7a5eee 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -21,7 +21,6 @@ #include "td/net/NetStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" #include "td/utils/BufferedFd.h" @@ -31,6 +30,7 @@ #include "td/utils/logging.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/net/DcAuthManager.h b/td/telegram/net/DcAuthManager.h index a6e21abda..2626db9c3 100644 --- a/td/telegram/net/DcAuthManager.h +++ b/td/telegram/net/DcAuthManager.h @@ -11,11 +11,11 @@ #include "td/telegram/net/NetQuery.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include <memory> diff --git a/td/telegram/net/NetQuery.h b/td/telegram/net/NetQuery.h index bc0edb3d0..d885bd784 100644 --- a/td/telegram/net/NetQuery.h +++ b/td/telegram/net/NetQuery.h @@ -11,7 +11,6 @@ #include "td/telegram/net/NetQueryStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" #include "td/utils/buffer.h" @@ -19,6 +18,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/ObjectPool.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Span.h" #include "td/utils/Status.h" diff --git a/td/telegram/net/NetQueryDispatcher.h b/td/telegram/net/NetQueryDispatcher.h index 236081cb0..737d7a748 100644 --- a/td/telegram/net/NetQueryDispatcher.h +++ b/td/telegram/net/NetQueryDispatcher.h @@ -10,9 +10,9 @@ #include "td/telegram/net/NetQuery.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Status.h" diff --git a/td/telegram/net/NetStatsManager.h b/td/telegram/net/NetStatsManager.h index a869aa1f2..a794addb1 100644 --- a/td/telegram/net/NetStatsManager.h +++ b/td/telegram/net/NetStatsManager.h @@ -13,8 +13,8 @@ #include "td/net/NetStats.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include <array> diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index 16ce9a5b1..d46779195 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -17,7 +17,6 @@ #include "td/mtproto/SessionConnection.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/CancellationToken.h" @@ -25,6 +24,7 @@ #include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashSet.h" #include "td/utils/List.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/VectorQueue.h" diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index cb2de374c..1e101f8a7 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -14,11 +14,10 @@ #include "td/telegram/Td.h" #include "td/telegram/UniqueId.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" diff --git a/tdactor/td/actor/MultiPromise.cpp b/tdactor/td/actor/MultiPromise.cpp index 5bf8d40bd..f78e0f016 100644 --- a/tdactor/td/actor/MultiPromise.cpp +++ b/tdactor/td/actor/MultiPromise.cpp @@ -28,7 +28,7 @@ Promise<Unit> MultiPromiseActor::get_promise() { future.set_event(EventCreator::raw(actor_id(), nullptr)); futures_.emplace_back(std::move(future)); LOG(DEBUG) << "Get promise #" << futures_.size() << " for " << name_; - return PromiseCreator::from_promise_actor(std::move(promise)); + return create_promise_from_promise_actor(std::move(promise)); } void MultiPromiseActor::raw_event(const Event::Raw &event) { diff --git a/tdactor/td/actor/MultiPromise.h b/tdactor/td/actor/MultiPromise.h index 88ac09e52..73b24d5d1 100644 --- a/tdactor/td/actor/MultiPromise.h +++ b/tdactor/td/actor/MultiPromise.h @@ -10,6 +10,7 @@ #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" namespace td { diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index fb81bced1..1a8940558 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -8,282 +8,10 @@ #include "td/actor/actor.h" -#include "td/utils/CancellationToken.h" -#include "td/utils/Closure.h" #include "td/utils/common.h" -#include "td/utils/invoke.h" -#include "td/utils/logging.h" -#include "td/utils/MovableValue.h" -#include "td/utils/ScopeGuard.h" -#include "td/utils/Status.h" - -#include <tuple> -#include <type_traits> -#include <utility> +#include "td/utils/Promise.h" namespace td { - -template <class T = Unit> -class PromiseInterface { - public: - PromiseInterface() = default; - PromiseInterface(const PromiseInterface &) = delete; - PromiseInterface &operator=(const PromiseInterface &) = delete; - PromiseInterface(PromiseInterface &&) = default; - PromiseInterface &operator=(PromiseInterface &&) = default; - virtual ~PromiseInterface() = default; - - virtual void set_value(T &&value) { - set_result(std::move(value)); - } - virtual void set_error(Status &&error) { - set_result(std::move(error)); - } - virtual void set_result(Result<T> &&result) { - if (result.is_ok()) { - set_value(result.move_as_ok()); - } else { - set_error(result.move_as_error()); - } - } - - virtual bool is_cancellable() const { - return false; - } - virtual bool is_canceled() const { - return false; - } -}; - -namespace detail { - -template <typename T> -struct GetArg final : public GetArg<decltype(&T::operator())> {}; - -template <class C, class R, class Arg> -class GetArg<R (C::*)(Arg)> { - public: - using type = Arg; -}; -template <class C, class R, class Arg> -class GetArg<R (C::*)(Arg) const> { - public: - using type = Arg; -}; - -template <class T> -using get_arg_t = std::decay_t<typename GetArg<T>::type>; - -template <class T> -struct DropResult { - using type = T; -}; - -template <class T> -struct DropResult<Result<T>> { - using type = T; -}; - -template <class T> -using drop_result_t = typename DropResult<T>::type; - -template <class ValueT, class FunctionT> -class LambdaPromise : public PromiseInterface<ValueT> { - enum class State : int32 { Empty, Ready, Complete }; - - public: - void set_value(ValueT &&value) override { - CHECK(state_.get() == State::Ready); - func_(std::move(value)); - state_ = State::Complete; - } - - void set_error(Status &&error) override { - if (state_.get() == State::Ready) { - do_error(std::move(error)); - state_ = State::Complete; - } - } - LambdaPromise(const LambdaPromise &other) = delete; - LambdaPromise &operator=(const LambdaPromise &other) = delete; - LambdaPromise(LambdaPromise &&other) = default; - LambdaPromise &operator=(LambdaPromise &&other) = default; - ~LambdaPromise() override { - if (state_.get() == State::Ready) { - do_error(Status::Error("Lost promise")); - } - } - - template <class FromT> - explicit LambdaPromise(FromT &&func) : func_(std::forward<FromT>(func)), state_(State::Ready) { - } - - private: - FunctionT func_; - MovableValue<State> state_{State::Empty}; - - template <class F = FunctionT> - std::enable_if_t<is_callable<F, Result<ValueT>>::value, void> do_error(Status &&status) { - func_(Result<ValueT>(std::move(status))); - } - template <class Y, class F = FunctionT> - std::enable_if_t<!is_callable<F, Result<ValueT>>::value, void> do_error(Y &&status) { - func_(Auto()); - } -}; -} // namespace detail - -template <class T> -class SafePromise; - -template <class T = Unit> -class Promise; - -template <class T> -struct is_promise_interface : std::false_type {}; - -template <class U> -struct is_promise_interface<PromiseInterface<U>> : std::true_type {}; - -template <class U> -struct is_promise_interface<Promise<U>> : std::true_type {}; - -template <class T> -struct is_promise_interface_ptr : std::false_type {}; - -template <class U> -struct is_promise_interface_ptr<unique_ptr<U>> : std::true_type {}; - -template <class T = void, class F = void, std::enable_if_t<std::is_same<T, void>::value, bool> has_t = false> -auto lambda_promise(F &&f) { - return detail::LambdaPromise<detail::drop_result_t<detail::get_arg_t<std::decay_t<F>>>, std::decay_t<F>>( - std::forward<F>(f)); -} -template <class T = void, class F = void, std::enable_if_t<!std::is_same<T, void>::value, bool> has_t = true> -auto lambda_promise(F &&f) { - return detail::LambdaPromise<T, std::decay_t<F>>(std::forward<F>(f)); -} - -template <class T, class F, - std::enable_if_t<is_promise_interface<std::decay_t<F>>::value, bool> from_promise_interface = true> -auto &&promise_interface(F &&f) { - return std::forward<F>(f); -} - -template <class T, class F, - std::enable_if_t<!is_promise_interface<std::decay_t<F>>::value, bool> from_promise_interface = false> -auto promise_interface(F &&f) { - return lambda_promise<T>(std::forward<F>(f)); -} - -template <class T, class F, - std::enable_if_t<is_promise_interface_ptr<std::decay_t<F>>::value, bool> from_promise_interface = true> -auto promise_interface_ptr(F &&f) { - return std::forward<F>(f); -} - -template <class T, class F, - std::enable_if_t<!is_promise_interface_ptr<std::decay_t<F>>::value, bool> from_promise_interface = false> -auto promise_interface_ptr(F &&f) { - return td::make_unique<std::decay_t<decltype(promise_interface<T>(std::forward<F>(f)))>>( - promise_interface<T>(std::forward<F>(f))); -} - -template <class T> -class Promise { - public: - void set_value(T &&value) { - if (!promise_) { - return; - } - promise_->set_value(std::move(value)); - promise_.reset(); - } - void set_error(Status &&error) { - if (!promise_) { - return; - } - promise_->set_error(std::move(error)); - promise_.reset(); - } - void set_result(Result<T> &&result) { - if (!promise_) { - return; - } - promise_->set_result(std::move(result)); - promise_.reset(); - } - void reset() { - promise_.reset(); - } - bool is_cancellable() const { - if (!promise_) { - return false; - } - return promise_->is_cancellable(); - } - bool is_canceled() const { - if (!promise_) { - return false; - } - return promise_->is_canceled(); - } - unique_ptr<PromiseInterface<T>> release() { - return std::move(promise_); - } - - Promise() = default; - explicit Promise(unique_ptr<PromiseInterface<T>> promise) : promise_(std::move(promise)) { - } - Promise(Auto) { - } - Promise(SafePromise<T> &&other); - Promise &operator=(SafePromise<T> &&other); - template <class F, std::enable_if_t<!std::is_same<std::decay_t<F>, Promise>::value, int> = 0> - Promise(F &&f) : promise_(promise_interface_ptr<T>(std::forward<F>(f))) { - } - - explicit operator bool() { - return static_cast<bool>(promise_); - } - - private: - unique_ptr<PromiseInterface<T>> promise_; -}; - - -template <class T = Unit> -class SafePromise { - public: - SafePromise(Promise<T> promise, Result<T> result) : promise_(std::move(promise)), result_(std::move(result)) { - } - SafePromise(const SafePromise &other) = delete; - SafePromise &operator=(const SafePromise &other) = delete; - SafePromise(SafePromise &&other) = default; - SafePromise &operator=(SafePromise &&other) = default; - ~SafePromise() { - if (promise_) { - promise_.set_result(std::move(result_)); - } - } - Promise<T> release() { - return std::move(promise_); - } - - private: - Promise<T> promise_; - Result<T> result_; -}; - -template <class T> -Promise<T>::Promise(SafePromise<T> &&other) : Promise(other.release()) { -} -template <class T> -Promise<T> &Promise<T>::operator=(SafePromise<T> &&other) { - *this = other.release(); - return *this; -} - namespace detail { class EventPromise final : public PromiseInterface<Unit> { @@ -323,40 +51,6 @@ class EventPromise final : public PromiseInterface<Unit> { } } }; - -template <class PromiseT> -class CancellablePromise final : public PromiseT { - public: - template <class... ArgsT> - CancellablePromise(CancellationToken cancellation_token, ArgsT &&...args) - : PromiseT(std::forward<ArgsT>(args)...), cancellation_token_(std::move(cancellation_token)) { - } - bool is_cancellable() const final { - return true; - } - bool is_canceled() const final { - return static_cast<bool>(cancellation_token_); - } - - private: - CancellationToken cancellation_token_; -}; - -template <class... ArgsT> -class JoinPromise final : public PromiseInterface<Unit> { - public: - explicit JoinPromise(ArgsT &&...arg) : promises_(std::forward<ArgsT>(arg)...) { - } - void set_value(Unit &&) final { - tuple_for_each(promises_, [](auto &promise) { promise.set_value(Unit()); }); - } - void set_error(Status &&error) final { - tuple_for_each(promises_, [&error](auto &promise) { promise.set_error(error.clone()); }); - } - - private: - std::tuple<std::decay_t<ArgsT>...> promises_; -}; } // namespace detail inline Promise<Unit> create_event_promise(EventFull &&ok) { @@ -367,31 +61,6 @@ 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 { - public: - template <class... ArgsT> - void operator()(ArgsT &&...args) const { - send_closure(std::forward<ArgsT>(args)...); - } -}; - -//template <class T> -//template <class... ArgsT> -//auto Promise<T>::send_closure(ArgsT &&... args) { -// return [promise = std::move(*this), t = std::make_tuple(std::forward<ArgsT>(args)...)](auto &&r_res) mutable { -// TRY_RESULT_PROMISE(promise, res, std::move(r_res)); -// td2::call_tuple(SendClosure(), std::tuple_cat(std::move(t), std::make_tuple(std::move(res), std::move(promise)))); -// }; -//} - -template <class... ArgsT> -auto promise_send_closure(ArgsT &&...args) { - return [t = std::make_tuple(std::forward<ArgsT>(args)...)](auto &&res) mutable { - call_tuple(SendClosure(), std::tuple_cat(std::move(t), std::make_tuple(std::forward<decltype(res)>(res)))); - }; -} - -/*** FutureActor and PromiseActor ***/ template <class T> class FutureActor; @@ -618,57 +287,9 @@ FutureActor<T> send_promise(ActorId<ActorAT> actor_id, ResultT (ActorBT::*func)( return pf.move_future(); } -class PromiseCreator { - public: - template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> - static Promise<ArgT> lambda(OkT &&ok) { - return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(std::forward<OkT>(ok))); - } - - template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> - static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) { - return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>( - std::move(cancellation_token), std::forward<OkT>(ok))); - } - - template <class... ArgsT> - static Promise<> join(ArgsT &&...args) { - return Promise<>(td::make_unique<detail::JoinPromise<ArgsT...>>(std::forward<ArgsT>(args)...)); - } - - template <class T> - static Promise<T> from_promise_actor(PromiseActor<T> &&from) { - return Promise<T>(td::make_unique<PromiseActor<T>>(std::move(from))); - } -}; - -inline void set_promises(vector<Promise<Unit>> &promises) { - auto moved_promises = std::move(promises); - promises.clear(); - - for (auto &promise : moved_promises) { - promise.set_value(Unit()); - } -} - template <class T> -void fail_promises(vector<Promise<T>> &promises, Status &&error) { - CHECK(error.is_error()); - auto moved_promises = std::move(promises); - promises.clear(); - - auto size = moved_promises.size(); - if (size == 0) { - return; - } - size--; - for (size_t i = 0; i < size; i++) { - auto &promise = moved_promises[i]; - if (promise) { - promise.set_error(error.clone()); - } - } - moved_promises[size].set_error(std::move(error)); +Promise<T> create_promise_from_promise_actor(PromiseActor<T> &&from) { + return Promise<T>(td::make_unique<PromiseActor<T>>(std::move(from))); } } // namespace td diff --git a/tdactor/td/actor/SleepActor.h b/tdactor/td/actor/SleepActor.h index 2c02db8af..8682ab0df 100644 --- a/tdactor/td/actor/SleepActor.h +++ b/tdactor/td/actor/SleepActor.h @@ -7,9 +7,9 @@ #pragma once #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" namespace td { diff --git a/tdactor/test/actors_simple.cpp b/tdactor/test/actors_simple.cpp index a76b80884..58f14ac48 100644 --- a/tdactor/test/actors_simple.cpp +++ b/tdactor/test/actors_simple.cpp @@ -16,6 +16,7 @@ #include "td/utils/Observer.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/thread.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 1759308cf..23419e950 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -11,14 +11,13 @@ #include "td/db/DbKey.h" #include "td/db/KeyValueSyncInterface.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/algorithm.h" #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/RwMutex.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" diff --git a/tddb/td/db/KeyValueSyncInterface.h b/tddb/td/db/KeyValueSyncInterface.h index 7aa553684..b73a7096d 100644 --- a/tddb/td/db/KeyValueSyncInterface.h +++ b/tddb/td/db/KeyValueSyncInterface.h @@ -6,9 +6,8 @@ // #pragma once -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include <unordered_map> diff --git a/tddb/td/db/SqliteKeyValueAsync.h b/tddb/td/db/SqliteKeyValueAsync.h index 530b3f1e0..e5bc29b1e 100644 --- a/tddb/td/db/SqliteKeyValueAsync.h +++ b/tddb/td/db/SqliteKeyValueAsync.h @@ -8,10 +8,9 @@ #include "td/db/SqliteKeyValueSafe.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" +#include "td/utils/Promise.h" #include <memory> diff --git a/tddb/td/db/TQueue.h b/tddb/td/db/TQueue.h index bde8730c0..934d8a02e 100644 --- a/tddb/td/db/TQueue.h +++ b/tddb/td/db/TQueue.h @@ -6,9 +6,8 @@ // #pragma once -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Span.h" #include "td/utils/Status.h" diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index 14dbcf14f..88dbacf58 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -9,8 +9,6 @@ #include "td/db/binlog/BinlogEvent.h" #include "td/db/DbKey.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/AesCtrByteFlow.h" #include "td/utils/buffer.h" #include "td/utils/BufferedFd.h" @@ -19,6 +17,7 @@ #include "td/utils/crypto.h" #include "td/utils/logging.h" #include "td/utils/port/FileFd.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" diff --git a/tddb/td/db/binlog/BinlogHelper.h b/tddb/td/db/binlog/BinlogHelper.h index aaeee7b51..66a65e060 100644 --- a/tddb/td/db/binlog/BinlogHelper.h +++ b/tddb/td/db/binlog/BinlogHelper.h @@ -9,9 +9,8 @@ #include "td/db/binlog/BinlogEvent.h" #include "td/db/binlog/BinlogInterface.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/StorerBase.h" namespace td { diff --git a/tddb/td/db/binlog/BinlogInterface.h b/tddb/td/db/binlog/BinlogInterface.h index 9ef596a15..b3ec7b119 100644 --- a/tddb/td/db/binlog/BinlogInterface.h +++ b/tddb/td/db/binlog/BinlogInterface.h @@ -9,10 +9,9 @@ #include "td/db/binlog/BinlogEvent.h" #include "td/db/DbKey.h" -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/StorerBase.h" namespace td { diff --git a/tddb/td/db/binlog/ConcurrentBinlog.h b/tddb/td/db/binlog/ConcurrentBinlog.h index 3db87516a..ad6c9bc5c 100644 --- a/tddb/td/db/binlog/ConcurrentBinlog.h +++ b/tddb/td/db/binlog/ConcurrentBinlog.h @@ -11,10 +11,10 @@ #include "td/db/DbKey.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/tdnet/td/net/DarwinHttp.h b/tdnet/td/net/DarwinHttp.h index 4d5447f74..42c0a5b00 100644 --- a/tdnet/td/net/DarwinHttp.h +++ b/tdnet/td/net/DarwinHttp.h @@ -6,9 +6,8 @@ // #pragma once -#include "td/actor/PromiseFuture.h" - #include "td/utils/buffer.h" +#include "td/utils/Promise.h" #include "td/utils/Slice.h" namespace td { diff --git a/tdnet/td/net/GetHostByNameActor.h b/tdnet/td/net/GetHostByNameActor.h index 4acef459e..f864b13e3 100644 --- a/tdnet/td/net/GetHostByNameActor.h +++ b/tdnet/td/net/GetHostByNameActor.h @@ -7,11 +7,11 @@ #pragma once #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/FlatHashMap.h" #include "td/utils/logging.h" #include "td/utils/port/IPAddress.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/tdnet/td/net/Wget.h b/tdnet/td/net/Wget.h index 98d1d1e0f..9372b4d58 100644 --- a/tdnet/td/net/Wget.h +++ b/tdnet/td/net/Wget.h @@ -11,9 +11,9 @@ #include "td/net/SslStream.h" #include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Promise.h" #include "td/utils/Status.h" #include <utility> diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index ae2b3ba08..c0d26b9ec 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -250,6 +250,7 @@ set(TDUTILS_SOURCE td/utils/overloaded.h td/utils/Parser.h td/utils/PathView.h + td/utils/Promise.h td/utils/queue.h td/utils/Random.h td/utils/ScopeGuard.h diff --git a/tdutils/td/utils/Promise.h b/tdutils/td/utils/Promise.h new file mode 100644 index 000000000..7746bc0ae --- /dev/null +++ b/tdutils/td/utils/Promise.h @@ -0,0 +1,393 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// 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) +// +#pragma once + +#include "td/utils/CancellationToken.h" +#include "td/utils/Closure.h" +#include "td/utils/common.h" +#include "td/utils/invoke.h" +#include "td/utils/logging.h" +#include "td/utils/MovableValue.h" +#include "td/utils/ScopeGuard.h" +#include "td/utils/Status.h" + +#include <tuple> +#include <type_traits> +#include <utility> + +namespace td { + +template <class T = Unit> +class PromiseInterface { + public: + PromiseInterface() = default; + PromiseInterface(const PromiseInterface &) = delete; + PromiseInterface &operator=(const PromiseInterface &) = delete; + PromiseInterface(PromiseInterface &&) = default; + PromiseInterface &operator=(PromiseInterface &&) = default; + virtual ~PromiseInterface() = default; + + virtual void set_value(T &&value) { + set_result(std::move(value)); + } + virtual void set_error(Status &&error) { + set_result(std::move(error)); + } + virtual void set_result(Result<T> &&result) { + if (result.is_ok()) { + set_value(result.move_as_ok()); + } else { + set_error(result.move_as_error()); + } + } + + virtual bool is_cancellable() const { + return false; + } + virtual bool is_canceled() const { + return false; + } +}; + +namespace detail { + +template <typename T> +struct GetArg final : public GetArg<decltype(&T::operator())> {}; + +template <class C, class R, class Arg> +class GetArg<R (C::*)(Arg)> { + public: + using type = Arg; +}; +template <class C, class R, class Arg> +class GetArg<R (C::*)(Arg) const> { + public: + using type = Arg; +}; + +template <class T> +using get_arg_t = std::decay_t<typename GetArg<T>::type>; + +template <class T> +struct DropResult { + using type = T; +}; + +template <class T> +struct DropResult<Result<T>> { + using type = T; +}; + +template <class T> +using drop_result_t = typename DropResult<T>::type; + +template <class ValueT, class FunctionT> +class LambdaPromise : public PromiseInterface<ValueT> { + enum class State : int32 { Empty, Ready, Complete }; + + public: + void set_value(ValueT &&value) override { + CHECK(state_.get() == State::Ready); + func_(std::move(value)); + state_ = State::Complete; + } + + void set_error(Status &&error) override { + if (state_.get() == State::Ready) { + do_error(std::move(error)); + state_ = State::Complete; + } + } + LambdaPromise(const LambdaPromise &other) = delete; + LambdaPromise &operator=(const LambdaPromise &other) = delete; + LambdaPromise(LambdaPromise &&other) = default; + LambdaPromise &operator=(LambdaPromise &&other) = default; + ~LambdaPromise() override { + if (state_.get() == State::Ready) { + do_error(Status::Error("Lost promise")); + } + } + + template <class FromT> + explicit LambdaPromise(FromT &&func) : func_(std::forward<FromT>(func)), state_(State::Ready) { + } + + private: + FunctionT func_; + MovableValue<State> state_{State::Empty}; + + template <class F = FunctionT> + std::enable_if_t<is_callable<F, Result<ValueT>>::value, void> do_error(Status &&status) { + func_(Result<ValueT>(std::move(status))); + } + template <class Y, class F = FunctionT> + std::enable_if_t<!is_callable<F, Result<ValueT>>::value, void> do_error(Y &&status) { + func_(Auto()); + } +}; +} // namespace detail + +template <class T> +class SafePromise; + +template <class T = Unit> +class Promise; + +template <class T> +struct is_promise_interface : std::false_type {}; + +template <class U> +struct is_promise_interface<PromiseInterface<U>> : std::true_type {}; + +template <class U> +struct is_promise_interface<Promise<U>> : std::true_type {}; + +template <class T> +struct is_promise_interface_ptr : std::false_type {}; + +template <class U> +struct is_promise_interface_ptr<unique_ptr<U>> : std::true_type {}; + +template <class T = void, class F = void, std::enable_if_t<std::is_same<T, void>::value, bool> has_t = false> +auto lambda_promise(F &&f) { + return detail::LambdaPromise<detail::drop_result_t<detail::get_arg_t<std::decay_t<F>>>, std::decay_t<F>>( + std::forward<F>(f)); +} +template <class T = void, class F = void, std::enable_if_t<!std::is_same<T, void>::value, bool> has_t = true> +auto lambda_promise(F &&f) { + return detail::LambdaPromise<T, std::decay_t<F>>(std::forward<F>(f)); +} + +template <class T, class F, + std::enable_if_t<is_promise_interface<std::decay_t<F>>::value, bool> from_promise_interface = true> +auto &&promise_interface(F &&f) { + return std::forward<F>(f); +} + +template <class T, class F, + std::enable_if_t<!is_promise_interface<std::decay_t<F>>::value, bool> from_promise_interface = false> +auto promise_interface(F &&f) { + return lambda_promise<T>(std::forward<F>(f)); +} + +template <class T, class F, + std::enable_if_t<is_promise_interface_ptr<std::decay_t<F>>::value, bool> from_promise_interface = true> +auto promise_interface_ptr(F &&f) { + return std::forward<F>(f); +} + +template <class T, class F, + std::enable_if_t<!is_promise_interface_ptr<std::decay_t<F>>::value, bool> from_promise_interface = false> +auto promise_interface_ptr(F &&f) { + return td::make_unique<std::decay_t<decltype(promise_interface<T>(std::forward<F>(f)))>>( + promise_interface<T>(std::forward<F>(f))); +} + +template <class T> +class Promise { + public: + void set_value(T &&value) { + if (!promise_) { + return; + } + promise_->set_value(std::move(value)); + promise_.reset(); + } + void set_error(Status &&error) { + if (!promise_) { + return; + } + promise_->set_error(std::move(error)); + promise_.reset(); + } + void set_result(Result<T> &&result) { + if (!promise_) { + return; + } + promise_->set_result(std::move(result)); + promise_.reset(); + } + void reset() { + promise_.reset(); + } + bool is_cancellable() const { + if (!promise_) { + return false; + } + return promise_->is_cancellable(); + } + bool is_canceled() const { + if (!promise_) { + return false; + } + return promise_->is_canceled(); + } + unique_ptr<PromiseInterface<T>> release() { + return std::move(promise_); + } + + Promise() = default; + explicit Promise(unique_ptr<PromiseInterface<T>> promise) : promise_(std::move(promise)) { + } + Promise(Auto) { + } + Promise(SafePromise<T> &&other); + Promise &operator=(SafePromise<T> &&other); + template <class F, std::enable_if_t<!std::is_same<std::decay_t<F>, Promise>::value, int> = 0> + Promise(F &&f) : promise_(promise_interface_ptr<T>(std::forward<F>(f))) { + } + + explicit operator bool() { + return static_cast<bool>(promise_); + } + + private: + unique_ptr<PromiseInterface<T>> promise_; +}; + +template <class T = Unit> +class SafePromise { + public: + SafePromise(Promise<T> promise, Result<T> result) : promise_(std::move(promise)), result_(std::move(result)) { + } + SafePromise(const SafePromise &other) = delete; + SafePromise &operator=(const SafePromise &other) = delete; + SafePromise(SafePromise &&other) = default; + SafePromise &operator=(SafePromise &&other) = default; + ~SafePromise() { + if (promise_) { + promise_.set_result(std::move(result_)); + } + } + Promise<T> release() { + return std::move(promise_); + } + + private: + Promise<T> promise_; + Result<T> result_; +}; + +template <class T> +Promise<T>::Promise(SafePromise<T> &&other) : Promise(other.release()) { +} + +template <class T> +Promise<T> &Promise<T>::operator=(SafePromise<T> &&other) { + *this = other.release(); + return *this; +} + +namespace detail { +template <class PromiseT> +class CancellablePromise final : public PromiseT { + public: + template <class... ArgsT> + CancellablePromise(CancellationToken cancellation_token, ArgsT &&...args) + : PromiseT(std::forward<ArgsT>(args)...), cancellation_token_(std::move(cancellation_token)) { + } + bool is_cancellable() const final { + return true; + } + bool is_canceled() const final { + return static_cast<bool>(cancellation_token_); + } + + private: + CancellationToken cancellation_token_; +}; + +template <class... ArgsT> +class JoinPromise final : public PromiseInterface<Unit> { + public: + explicit JoinPromise(ArgsT &&...arg) : promises_(std::forward<ArgsT>(arg)...) { + } + void set_value(Unit &&) final { + tuple_for_each(promises_, [](auto &promise) { promise.set_value(Unit()); }); + } + void set_error(Status &&error) final { + tuple_for_each(promises_, [&error](auto &promise) { promise.set_error(error.clone()); }); + } + + private: + std::tuple<std::decay_t<ArgsT>...> promises_; +}; +} // namespace detail + +class SendClosure { + public: + template <class... ArgsT> + void operator()(ArgsT &&...args) const { + send_closure(std::forward<ArgsT>(args)...); + } +}; + +//template <class T> +//template <class... ArgsT> +//auto Promise<T>::send_closure(ArgsT &&... args) { +// return [promise = std::move(*this), t = std::make_tuple(std::forward<ArgsT>(args)...)](auto &&r_res) mutable { +// TRY_RESULT_PROMISE(promise, res, std::move(r_res)); +// call_tuple(SendClosure(), std::tuple_cat(std::move(t), std::make_tuple(std::move(res), std::move(promise)))); +// }; +//} + +template <class... ArgsT> +auto promise_send_closure(ArgsT &&...args) { + return [t = std::make_tuple(std::forward<ArgsT>(args)...)](auto &&res) mutable { + call_tuple(SendClosure(), std::tuple_cat(std::move(t), std::make_tuple(std::forward<decltype(res)>(res)))); + }; +} + +class PromiseCreator { + public: + template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> + static Promise<ArgT> lambda(OkT &&ok) { + return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(std::forward<OkT>(ok))); + } + + template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> + static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) { + return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>( + std::move(cancellation_token), std::forward<OkT>(ok))); + } + + template <class... ArgsT> + static Promise<> join(ArgsT &&...args) { + return Promise<>(td::make_unique<detail::JoinPromise<ArgsT...>>(std::forward<ArgsT>(args)...)); + } +}; + +inline void set_promises(vector<Promise<Unit>> &promises) { + auto moved_promises = std::move(promises); + promises.clear(); + + for (auto &promise : moved_promises) { + promise.set_value(Unit()); + } +} + +template <class T> +void fail_promises(vector<Promise<T>> &promises, Status &&error) { + CHECK(error.is_error()); + auto moved_promises = std::move(promises); + promises.clear(); + + auto size = moved_promises.size(); + if (size == 0) { + return; + } + size--; + for (size_t i = 0; i < size; i++) { + auto &promise = moved_promises[i]; + if (promise) { + promise.set_error(error.clone()); + } + } + moved_promises[size].set_error(std::move(error)); +} + +} // namespace td diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 58eff4356..4f7e5c3f1 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -29,7 +29,6 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/base64.h" #include "td/utils/BufferedFd.h" @@ -39,6 +38,7 @@ #include "td/utils/port/Clocks.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" +#include "td/utils/Promise.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" diff --git a/test/online.cpp b/test/online.cpp index 97e39df26..50b87081e 100644 --- a/test/online.cpp +++ b/test/online.cpp @@ -12,7 +12,6 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" #include "td/actor/MultiPromise.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/crypto.h" #include "td/utils/FileLog.h" @@ -21,6 +20,7 @@ #include "td/utils/OptionParser.h" #include "td/utils/port/path.h" #include "td/utils/port/signals.h" +#include "td/utils/Promise.h" #include "td/utils/Random.h" #include <iostream> diff --git a/test/secret.cpp b/test/secret.cpp index bc1d03a91..3c1d351ea 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -26,7 +26,6 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" -#include "td/actor/PromiseFuture.h" #include "td/utils/algorithm.h" #include "td/utils/as.h" @@ -38,6 +37,7 @@ #include "td/utils/Gzip.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/Promise.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 3a00549d6..81cb2aad4 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -26,6 +26,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/sleep.h" #include "td/utils/port/thread.h" +#include "td/utils/Promise.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" |
