enhance Future::Then()

This commit is contained in:
2022-09-25 23:40:44 +09:00
parent 8ffad3347f
commit 2082a6e482
4 changed files with 72 additions and 46 deletions

View File

@@ -163,11 +163,11 @@ class Node::Lambda final : public nf7::Node::Lambda,
f_->factory_ = b.Build();
b.Send("create", nf7::Value::Pulse {});
f_->fu_->ThenSub(self, [this](auto) { if (f_) f_->factory_ = nullptr; });
f_->fu_->Then(self, [this](auto) { if (f_) f_->factory_ = nullptr; });
}
assert(f_->fu_);
f_->fu_->ThenSub(self, [this, k = std::string {k}, v = v, caller](auto fu) mutable {
f_->fu_->Then(self, [this, k = std::string {k}, v = v, caller](auto fu) mutable {
try {
auto ref = fu.value().template data<nf7::luajit::Ref>();
CallFunc(ref, std::move(k), std::move(v), caller);

View File

@@ -256,8 +256,7 @@ class NFile::Lambda final : public nf7::Node::Lambda,
lock_ = f_->mtx_.AcquireLock(ex);
}
auto self = shared_from_this();
lock_->Then([self, this, caller, f = std::move(f)](auto fu) mutable {
const auto k = fu.value();
lock_->ThenIf([self, this, caller, f = std::move(f)](auto&) mutable {
f_->th_->Push(self, NFile::Runner::Task {
.callee = self,
.caller = std::move(caller),