Commit f4397a2e authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Use via() in window()

Summary: This makes it work for SemiFutures with deferred work.

Reviewed By: yfeldblum

Differential Revision: D12982589

fbshipit-source-id: 9dcd130c72e8df67e8b4773b228041f96da06b10
parent ef2774e4
......@@ -1826,16 +1826,13 @@ window(Executor::KeepAlive<> executor, Collection input, F func, size_t n) {
static void spawn(std::shared_ptr<WindowContext> ctx) {
size_t i = ctx->i.fetch_add(1, std::memory_order_relaxed);
if (i < ctx->input.size()) {
auto fut = makeSemiFutureWith(
[&] { return ctx->func(std::move(ctx->input[i])); });
fut.setCallback_([ctx = std::move(ctx), i](Try<Result>&& t) mutable {
ctx->executor->add(
[ctx = std::move(ctx), i, t = std::move(t)]() mutable {
makeSemiFutureWith([&] { return ctx->func(std::move(ctx->input[i])); })
.via(ctx->executor.get())
.setCallback_([ctx = std::move(ctx), i](Try<Result>&& t) mutable {
ctx->promises[i].setTry(std::move(t));
// Chain another future onto this one
spawn(std::move(ctx));
});
});
}
}
};
......
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