parseq icon indicating copy to clipboard operation
parseq copied to clipboard

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

Open haiweiwang73 opened this issue 6 years ago • 1 comments

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();
        });

haiweiwang73 avatar Jun 13 '19 17:06 haiweiwang73

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)

hiteshsharma avatar Jul 31 '20 16:07 hiteshsharma