Skip to content

Executor of packaged_task not used in reduction #502

@aaronalbers

Description

@aaronalbers

I am not sure what the intended functionality is here but it was my understanding that the executor passed to stlab::package() would be used when executing a continuation.
Does a future reduction not count as a continuation?
I think it did in 1.6.2 since I now have code that doesn't work when I updated to 1.7.1.
Should I update my usage or was this change unintended?

BOOST_AUTO_TEST_CASE(continuation_with_custom_executor) {
    BOOST_TEST_MESSAGE("running continuation through custom executor");

    std::atomic_int check{0};
    auto func = [&check]() mutable {
        ++check;
    };
    
    auto pf = package<void(void)>([&](auto f){
      func(); // Should run once during the continuation
      default_executor(std::move(f));
    }, []{});
    auto f = pf.second.then([]{});
    pf.first();
    
    static_cast<void>(stlab::await(f));

    BOOST_REQUIRE_EQUAL(1, check); // This passes
}

BOOST_AUTO_TEST_CASE(continuation_with_custom_executor_future_reduction) {
    BOOST_TEST_MESSAGE("running continuation through custom executor with future reduction");

    std::atomic_int check{0};
    auto func = [&check]() mutable {
        ++check;
    };
    
    auto pf = package<void(void)>([&](auto f){
      func(); // Should run once during the continuation
      default_executor(std::move(f));
    }, []{});
    auto f = stlab::async(stlab::default_executor, []{}).then([f = std::move(pf.second)](){ return f; });
    pf.first();
    
    static_cast<void>(stlab::await(f));

    BOOST_REQUIRE_EQUAL(1, check); // This fails but I think it used to pass (or at least used the executor)
}

BOOST_AUTO_TEST_CASE(continuation_with_custom_executor_future_reduction_and_continuation) {
    BOOST_TEST_MESSAGE("running continuation through custom executor with future reduction and continuation");

    std::atomic_int check{0};
    auto func = [&check]() mutable {
        ++check;
    };
    
    auto pf = package<void(void)>([&](auto f){
      func(); // Should run once during the continuation
      default_executor(std::move(f));
    }, []{});
    auto f = stlab::async(stlab::default_executor, []{}).then([f = std::move(pf.second)](){ return f.then([]{}); });
    pf.first();
    
    static_cast<void>(stlab::await(f));

    BOOST_REQUIRE_EQUAL(2, check); // This fails but I think it used to pass (or at least used the executor more than once)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions