Commit 36602b54 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let window work with functions returning SemiFuture

Summary: [Folly] Let `window` work with functions returning `SemiFuture`.

Reviewed By: LeeHowes

Differential Revision: D8505836

fbshipit-source-id: 51c14b131760528eb6c367298cb23c4deec30ab3
parent dd674591
......@@ -1639,8 +1639,8 @@ window(Executor* executor, Collection input, F func, size_t n) {
static void spawn(std::shared_ptr<WindowContext> ctx) {
size_t i = ctx->i++;
if (i < ctx->input.size()) {
auto fut =
makeFutureWith([&] { return ctx->func(std::move(ctx->input[i])); });
auto fut = makeSemiFutureWith(
[&] { return ctx->func(std::move(ctx->input[i])); });
fut.setCallback_([ctx = std::move(ctx), i](Try<Result>&& t) mutable {
const auto executor_ = ctx->executor;
executor_->add([ctx = std::move(ctx), i, t = std::move(t)]() mutable {
......
......@@ -82,6 +82,20 @@ TEST(Window, basic) {
}).get();
EXPECT_EQ(6, res);
}
{
// string -> return SemiFuture<int>
auto res = reduce(
window(
std::vector<std::string>{"1", "2", "3"},
[](std::string s) {
return makeSemiFuture<int>(folly::to<int>(s));
},
2),
0,
[](int sum, const Try<int>& b) { return sum + *b; })
.get();
EXPECT_EQ(6, res);
}
{
SCOPED_TRACE("repeat same fn");
auto res = reduce(
......
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