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