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