Add LambdaPromise debug.
This commit is contained in:
parent
1147dfc6fb
commit
942e5fc613
@ -95,7 +95,7 @@ class Actor : public ObserverBase {
|
||||
auto self_closure(SelfT *self, FuncT &&func, ArgsT &&...args);
|
||||
|
||||
template <class LambdaT>
|
||||
auto self_lambda(LambdaT &&lambda);
|
||||
auto self_lambda(LambdaT &&func);
|
||||
|
||||
// proxy to info_
|
||||
ActorId<> actor_id();
|
||||
|
@ -156,8 +156,8 @@ auto Actor::self_closure(SelfT *self, FuncT &&func, ArgsT &&...args) {
|
||||
}
|
||||
|
||||
template <class LambdaT>
|
||||
auto Actor::self_lambda(LambdaT &&lambda) {
|
||||
return EventCreator::lambda(actor_id(), std::forward<LambdaT>(lambda));
|
||||
auto Actor::self_lambda(LambdaT &&func) {
|
||||
return EventCreator::from_lambda(actor_id(), std::forward<LambdaT>(func));
|
||||
}
|
||||
|
||||
inline Slice Actor::get_name() const {
|
||||
|
@ -89,7 +89,7 @@ class LambdaEvent final : public CustomEvent {
|
||||
f_();
|
||||
}
|
||||
template <class FromLambdaT, std::enable_if_t<!std::is_same<std::decay_t<FromLambdaT>, LambdaEvent>::value, int> = 0>
|
||||
explicit LambdaEvent(FromLambdaT &&lambda) : f_(std::forward<FromLambdaT>(lambda)) {
|
||||
explicit LambdaEvent(FromLambdaT &&func) : f_(std::forward<FromLambdaT>(func)) {
|
||||
}
|
||||
|
||||
private:
|
||||
@ -149,8 +149,8 @@ class Event {
|
||||
}
|
||||
|
||||
template <class FromLambdaT>
|
||||
static Event lambda(FromLambdaT &&lambda) {
|
||||
return custom(new LambdaEvent<std::decay_t<FromLambdaT>>(std::forward<FromLambdaT>(lambda)));
|
||||
static Event from_lambda(FromLambdaT &&func) {
|
||||
return custom(new LambdaEvent<std::decay_t<FromLambdaT>>(std::forward<FromLambdaT>(func)));
|
||||
}
|
||||
|
||||
Event() : Event(Type::NoType) {
|
||||
|
@ -65,8 +65,8 @@ class EventCreator {
|
||||
}
|
||||
|
||||
template <class LambdaT>
|
||||
static EventFull lambda(ActorRef actor_ref, LambdaT &&lambda) {
|
||||
return EventFull(actor_ref, Event::lambda(std::forward<LambdaT>(lambda)));
|
||||
static EventFull from_lambda(ActorRef actor_ref, LambdaT &&func) {
|
||||
return EventFull(actor_ref, Event::from_lambda(std::forward<LambdaT>(func)));
|
||||
}
|
||||
|
||||
static EventFull yield(ActorRef actor_ref) {
|
||||
|
@ -107,7 +107,7 @@ class Scheduler {
|
||||
void destroy_on_scheduler(int32 sched_id, ArgsT &...values);
|
||||
|
||||
template <ActorSendType send_type, class EventT>
|
||||
void send_lambda(ActorRef actor_ref, EventT &&lambda);
|
||||
void send_lambda(ActorRef actor_ref, EventT &&func);
|
||||
|
||||
template <ActorSendType send_type, class EventT>
|
||||
void send_closure(ActorRef actor_ref, EventT &&closure);
|
||||
|
@ -215,15 +215,15 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
|
||||
}
|
||||
|
||||
template <ActorSendType send_type, class EventT>
|
||||
void Scheduler::send_lambda(ActorRef actor_ref, EventT &&lambda) {
|
||||
void Scheduler::send_lambda(ActorRef actor_ref, EventT &&func) {
|
||||
return send_impl<send_type>(
|
||||
actor_ref.get(),
|
||||
[&](ActorInfo *actor_info) {
|
||||
event_context_ptr_->link_token = actor_ref.token();
|
||||
lambda();
|
||||
func();
|
||||
},
|
||||
[&] {
|
||||
auto event = Event::lambda(std::forward<EventT>(lambda));
|
||||
auto event = Event::from_lambda(std::forward<EventT>(func));
|
||||
event.set_link_token(actor_ref.token());
|
||||
return event;
|
||||
});
|
||||
|
@ -94,7 +94,7 @@ class LambdaPromise : public PromiseInterface<ValueT> {
|
||||
|
||||
public:
|
||||
void set_value(ValueT &&value) override {
|
||||
CHECK(state_.get() == State::Ready);
|
||||
CHECK_IMPL(state_.get() == State::Ready, file_, line_);
|
||||
do_ok(std::move(value));
|
||||
state_ = State::Complete;
|
||||
}
|
||||
@ -116,12 +116,15 @@ class LambdaPromise : public PromiseInterface<ValueT> {
|
||||
}
|
||||
|
||||
template <class FromT>
|
||||
explicit LambdaPromise(FromT &&func) : func_(std::forward<FromT>(func)), state_(State::Ready) {
|
||||
explicit LambdaPromise(const char *file, int line, FromT &&func)
|
||||
: func_(std::forward<FromT>(func)), state_(State::Ready), file_(file), line_(line) {
|
||||
}
|
||||
|
||||
private:
|
||||
FunctionT func_;
|
||||
MovableValue<State> state_{State::Empty};
|
||||
const char *file_ = "";
|
||||
int line_ = 0;
|
||||
|
||||
template <class F = FunctionT>
|
||||
std::enable_if_t<is_callable<F, Result<ValueT>>::value, void> do_error(Status &&status) {
|
||||
@ -158,11 +161,12 @@ 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 LambdaPromise<drop_result_t<get_arg_t<std::decay_t<F>>>, std::decay_t<F>>(std::forward<F>(f));
|
||||
return LambdaPromise<drop_result_t<get_arg_t<std::decay_t<F>>>, std::decay_t<F>>(__FILE__, __LINE__,
|
||||
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 LambdaPromise<T, std::decay_t<F>>(std::forward<F>(f));
|
||||
return LambdaPromise<T, std::decay_t<F>>(__FILE__, __LINE__, std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class T, class F,
|
||||
@ -325,15 +329,18 @@ class JoinPromise final : public PromiseInterface<Unit> {
|
||||
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)));
|
||||
static Promise<ArgT> lambda_impl(const char *file, int line, OkT &&ok) {
|
||||
return Promise<ArgT>(
|
||||
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>>>
|
||||
static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) {
|
||||
static auto cancellable_lambda_impl(const char *file, int line, 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)));
|
||||
std::move(cancellation_token), file, line, std::forward<OkT>(ok)));
|
||||
}
|
||||
#define cancellable_lambda(...) cancellable_lambda_impl(__FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
template <class... ArgsT>
|
||||
static Promise<> join(ArgsT &&...args) {
|
||||
|
@ -8,11 +8,13 @@
|
||||
|
||||
#define TD_DUMMY_CHECK(condition) ((void)(condition))
|
||||
|
||||
#define CHECK(condition) \
|
||||
if (!(condition)) { \
|
||||
::td::detail::process_check_error(#condition, __FILE__, __LINE__); \
|
||||
#define CHECK_IMPL(condition, file, line) \
|
||||
if (!(condition)) { \
|
||||
::td::detail::process_check_error(#condition, file, line); \
|
||||
}
|
||||
|
||||
#define CHECK(condition) CHECK_IMPL(condition, __FILE__, __LINE__)
|
||||
|
||||
// clang-format off
|
||||
#ifdef NDEBUG
|
||||
#define DCHECK TD_DUMMY_CHECK
|
||||
|
Loading…
Reference in New Issue
Block a user