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

Looking for solution to stop the task chain and not trigger onFailure or recover #221

Open
haiweiwang73 opened this issue Jun 13, 2019 · 1 comment

Comments

@haiweiwang73
Copy link

Is there a way to pause the task sequence, check condition and cancel out the sequence.

Task<OrderDatagram> t1 = Task.value(orderData);

        Task<OrderDatagram> t2 = t1.andThen( d -> d.setCurrency(Optional.of("dollars")));

        Task<OrderDatagram> t3 = t2.andThen( d -> {
            if(d.getCurrency().equals("dollars")){
                System.out.println("The verification is not passed throw error");
//// This is the part doesnt work as what I think it is. Is there a way to stop the process fro the rest of the task and not trigger the onFailure in temp ??
                t2.cancel(new OrderDatagramValidationException.Item.ExistsException(1,"abc",1));
            }
        });

        Task<OrderDatagram> temp =  t3.andThen( t -> {
            throw new Exception();
        }).onFailure( t->{
            throw new Exception();
        });
@hiteshsharma
Copy link
Contributor

you can do this

Task<OrderDatagram> t1 = Task.value(orderData)
  .map(d -> {
    if (d.getCurrency().equals("dollars")){
      throw new OrderDatagramValidationException.Item.ExistsException(1,"abc",1);
    }
    return d;
  });

Though note that this is not a good Parseq use case since there is no blocking execution involved (unless this was just a simple example you posted which isn't similar to the actual problem you're trying to solve)

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

No branches or pull requests

2 participants