tdesktop/Telegram/SourceFiles/rpl/deferred.h

27 lines
721 B
C
Raw Normal View History

2017-09-12 13:58:14 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-09-12 13:58:14 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-09-12 13:58:14 +00:00
*/
#pragma once
#include <rpl/producer.h>
namespace rpl {
template <
typename Creator,
typename Value = typename decltype(std::declval<Creator>()())::value_type,
typename Error = typename decltype(std::declval<Creator>()())::error_type>
2017-09-27 11:16:05 +00:00
inline auto deferred(Creator &&creator) {
return make_producer<Value, Error>([
creator = std::forward<Creator>(creator)
](const auto &consumer) mutable {
2017-09-12 13:58:14 +00:00
return std::move(creator)().start_existing(consumer);
2017-09-27 11:16:05 +00:00
});
2017-09-12 13:58:14 +00:00
}
} // namespace rpl