Commit 75aef07c authored by Dave Watson's avatar Dave Watson Committed by Alecs King

future / fiber integration

Summary:
make future::wait() use fiber's baton, so wait works in threads or in fibers.

Much cleaner than making a new FiberRequest type in thrift

Test Plan: tests

Reviewed By: andrii@fb.com

Subscribers: doug, alandau, bmatheny, mshneer, andrii, folly-diffs@, yitingli, yfeldblum, jsedgwick, chalfant

FB internal diff: D1996283

Signature: t1:1996283:1429144165:da5dc6b1f2a053a45efd39877e79169e3fba810c
parent 312e7454
......@@ -19,7 +19,7 @@
#include <chrono>
#include <thread>
#include <folly/Baton.h>
#include <folly/experimental/fibers/Baton.h>
#include <folly/Optional.h>
#include <folly/futures/detail/Core.h>
#include <folly/futures/Timekeeper.h>
......@@ -896,7 +896,7 @@ void waitImpl(Future<T>& f) {
// short-circuit if there's nothing to do
if (f.isReady()) return;
Baton<> baton;
folly::fibers::Baton baton;
f = f.then([&](Try<T> t) {
baton.post();
return makeFuture(std::move(t));
......@@ -916,7 +916,7 @@ void waitImpl(Future<T>& f, Duration dur) {
// short-circuit if there's nothing to do
if (f.isReady()) return;
auto baton = std::make_shared<Baton<>>();
auto baton = std::make_shared<folly::fibers::Baton>();
f = f.then([baton](Try<T> t) {
baton->post();
return makeFuture(std::move(t));
......@@ -925,7 +925,7 @@ void waitImpl(Future<T>& f, Duration dur) {
// Let's preserve the invariant that if we did not timeout (timed_wait returns
// true), then the returned Future is complete when it is returned to the
// caller. We need to wait out the race for that Future to complete.
if (baton->timed_wait(std::chrono::system_clock::now() + dur)) {
if (baton->timed_wait(dur)) {
while (!f.isReady()) {
std::this_thread::yield();
}
......
......@@ -29,6 +29,7 @@
#include <folly/futures/ManualExecutor.h>
#include <folly/futures/DrivableExecutor.h>
#include <folly/dynamic.h>
#include <folly/Baton.h>
#include <folly/MPMCQueue.h>
#include <folly/io/async/EventBase.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