Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduction does not appear to work for failed futures #113

Closed
Frans-Willem opened this issue Dec 9, 2017 · 2 comments
Closed

Reduction does not appear to work for failed futures #113

Frans-Willem opened this issue Dec 9, 2017 · 2 comments

Comments

@Frans-Willem
Copy link
Contributor

The following code works, and prints both "Recover on test called" and "Recover on package called"

  // Make a ready resolved future
  auto test = stlab::make_ready_future(stlab::immediate_executor);
  // Create a future that we'll resolve later.
  auto package = stlab::package<void()>(stlab::immediate_executor, []() {});
  // Chain this to-be-resolved future after test.
  test.then([package]() { return package.second; })
      // Chain something to catch resolves/rejections
      .recover([](stlab::future<void> f) {
        std::cout << "Recover on test called" << std::endl;
      })
      .detach();
  // Also stay informed of the package:
  package.second.recover([](stlab::future<void> f) {
    std::cout << "Recover on package called" << std::endl;
  }).detach();
  // Now resolve the chained future.
  package.first();

However, if we have the inner package fail, it will only print "Recover on package called":

  // Make a ready resolved future
  auto test = stlab::make_ready_future(stlab::immediate_executor);
  // Create a future that we'll resolve later.
  auto package = stlab::package<void()>(stlab::immediate_executor, []() {throw std::runtime_error("Oops");});
  // Chain this to-be-resolved future after test.
  test.then([package]() { return package.second; })
      // Chain something to catch resolves/rejections
      .recover([](stlab::future<void> f) {
        std::cout << "Recover on test called" << std::endl;
      })
      .detach();
  // Also stay informed of the package:
  package.second.recover([](stlab::future<void> f) {
    std::cout << "Recover on package called" << std::endl;
  }).detach();
  // Now resolve the chained future.
  package.first();

I'm running a clone from the master branch that is up to date as of today...

@Frans-Willem
Copy link
Contributor Author

More debugging shows that this only fails when the type of the package is void. When changing to int, things work fine.

@FelixPetriconi
Copy link
Member

Frans-Willem, many thanks for the PR!
Fixed in 1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants