Commit d475caca authored by Kenton Varda's avatar Kenton Varda

Fix GCC.

parent 51c2b855
......@@ -686,27 +686,17 @@ public:
// Get the EventLoop in which this value can be modified.
template <typename Func>
PromiseForResult<Func, T&> applyNow(Func&& func) const KJ_WARN_UNUSED_RESULT {
PromiseForResult<Func, T&> applyNow(Func&& func) const KJ_WARN_UNUSED_RESULT;
// Calls the given function, passing the guarded object to it as a mutable reference, and
// returning a pointer to the function's result. When called from within the object's event
// loop, the function runs synchronously, but when called from any other thread, the function
// is queued to run on the object's loop later.
if (loop.isCurrent()) {
return func(const_cast<T&>(value));
} else {
return applyLater(kj::fwd<Func>(func));
}
}
template <typename Func>
PromiseForResult<Func, T&> applyLater(Func&& func) const KJ_WARN_UNUSED_RESULT {
PromiseForResult<Func, T&> applyLater(Func&& func) const KJ_WARN_UNUSED_RESULT;
// Like `applyNow` but always queues the function to run later regardless of which thread
// called it.
return loop.evalLater(Capture<Func> { const_cast<T&>(value), kj::fwd<Func>(func) });
}
private:
const EventLoop& loop;
T value;
......@@ -1597,6 +1587,30 @@ PromiseFulfillerPair<T> newPromiseAndFulfiller(const EventLoop& loop) {
return PromiseFulfillerPair<T> { kj::mv(promise), kj::mv(wrapper) };
}
template <typename T>
template <typename Func>
PromiseForResult<Func, T&> EventLoopGuarded<T>::applyNow(Func&& func) const {
// Calls the given function, passing the guarded object to it as a mutable reference, and
// returning a pointer to the function's result. When called from within the object's event
// loop, the function runs synchronously, but when called from any other thread, the function
// is queued to run on the object's loop later.
if (loop.isCurrent()) {
return func(const_cast<T&>(value));
} else {
return applyLater(kj::fwd<Func>(func));
}
}
template <typename T>
template <typename Func>
PromiseForResult<Func, T&> EventLoopGuarded<T>::applyLater(Func&& func) const {
// Like `applyNow` but always queues the function to run later regardless of which thread
// called it.
return loop.evalLater(Capture<Func> { const_cast<T&>(value), kj::fwd<Func>(func) });
}
} // namespace kj
#endif // KJ_ASYNC_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment