/// time there won't be any problems.
template<typename T>
class Core {
+ static_assert(!std::is_void<T>::value,
+ "void futures are not supported. Use Unit instead.");
public:
/// This must be heap-constructed. There's probably a way to enforce that in
/// code but since this is just internal detail code and I don't know how
/// off-hand, I'm punting.
- Core() {}
+ Core() : result_(), fsm_(State::Start), attached_(2) {}
explicit Core(Try<T>&& t)
: result_(std::move(t)),
}
void doCallback() {
- RequestContext::setContext(context_);
-
Executor* x = executor_;
int8_t priority;
if (x) {
if (LIKELY(x->getNumPriorities() == 1)) {
x->add([this]() mutable {
SCOPE_EXIT { detachOne(); };
+ RequestContext::setContext(context_);
callback_(std::move(*result_));
});
} else {
x->addWithPriority([this]() mutable {
SCOPE_EXIT { detachOne(); };
+ RequestContext::setContext(context_);
callback_(std::move(*result_));
}, priority);
}
} catch (...) {
+ --attached_; // Account for extra ++attached_ before try
+ RequestContext::setContext(context_);
result_ = Try<T>(exception_wrapper(std::current_exception()));
callback_(std::move(*result_));
}
} else {
+ RequestContext::setContext(context_);
callback_(std::move(*result_));
}
}
char lambdaBuf_[lambdaBufSize];
// place result_ next to increase the likelihood that the value will be
// contained entirely in one cache line
- folly::Optional<Try<T>> result_ {};
+ folly::Optional<Try<T>> result_;
std::function<void(Try<T>&&)> callback_ {nullptr};
- FSM<State> fsm_ {State::Start};
- std::atomic<unsigned char> attached_ {2};
+ FSM<State> fsm_;
+ std::atomic<unsigned char> attached_;
std::atomic<bool> active_ {true};
std::atomic<bool> interruptHandlerSet_ {false};
folly::MicroSpinLock interruptLock_ {0};