Remove LambdaPromise debug to avoid compiler errors because of #define lambda(...).

This commit is contained in:
levlam 2024-02-22 00:57:54 +03:00
parent 62d87ab433
commit ba2f63f8b0

View File

@ -94,7 +94,7 @@ class LambdaPromise : public PromiseInterface<ValueT> {
public: public:
void set_value(ValueT &&value) override { void set_value(ValueT &&value) override {
CHECK_IMPL(state_.get() == State::Ready, file_, line_); CHECK(state_.get() == State::Ready);
do_ok(std::move(value)); do_ok(std::move(value));
state_ = State::Complete; state_ = State::Complete;
} }
@ -116,15 +116,12 @@ class LambdaPromise : public PromiseInterface<ValueT> {
} }
template <class FromT> template <class FromT>
LambdaPromise(const char *file, int line, FromT &&func) LambdaPromise(FromT &&func) : func_(std::forward<FromT>(func)), state_(State::Ready) {
: func_(std::forward<FromT>(func)), state_(State::Ready), file_(file), line_(line) {
} }
private: private:
FunctionT func_; FunctionT func_;
MovableValue<State> state_{State::Empty}; MovableValue<State> state_{State::Empty};
const char *file_ = "";
int line_ = 0;
template <class F = FunctionT> template <class F = FunctionT>
std::enable_if_t<is_callable<F, Result<ValueT>>::value, void> do_error(Status &&status) { std::enable_if_t<is_callable<F, Result<ValueT>>::value, void> do_error(Status &&status) {
@ -161,12 +158,11 @@ 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> 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) { auto lambda_promise(F &&f) {
return LambdaPromise<drop_result_t<get_arg_t<std::decay_t<F>>>, std::decay_t<F>>(__FILE__, __LINE__, return LambdaPromise<drop_result_t<get_arg_t<std::decay_t<F>>>, std::decay_t<F>>(std::forward<F>(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> 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) { auto lambda_promise(F &&f) {
return LambdaPromise<T, std::decay_t<F>>(__FILE__, __LINE__, std::forward<F>(f)); return LambdaPromise<T, std::decay_t<F>>(std::forward<F>(f));
} }
template <class T, class F, template <class T, class F,
@ -329,18 +325,15 @@ class JoinPromise final : public PromiseInterface<Unit> {
class PromiseCreator { class PromiseCreator {
public: public:
template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>>
static Promise<ArgT> lambda_impl(const char *file, int line, OkT &&ok) { static Promise<ArgT> lambda(OkT &&ok) {
return Promise<ArgT>( return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(std::forward<OkT>(ok)));
td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(file, line, std::forward<OkT>(ok)));
} }
#define lambda(...) lambda_impl(__FILE__, __LINE__, __VA_ARGS__)
template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>>
static auto cancellable_lambda_impl(const char *file, int line, CancellationToken cancellation_token, OkT &&ok) { static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) {
return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>( return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>(
std::move(cancellation_token), file, line, std::forward<OkT>(ok))); std::move(cancellation_token), std::forward<OkT>(ok)));
} }
#define cancellable_lambda(...) cancellable_lambda_impl(__FILE__, __LINE__, __VA_ARGS__)
template <class... ArgsT> template <class... ArgsT>
static Promise<> join(ArgsT &&...args) { static Promise<> join(ArgsT &&...args) {