Usage of Stream.forEachUntilCancelled

Brian Goetz brian.goetz at
Sun Mar 24 06:43:45 PDT 2013

You're thinking sequentially.  How would "when does the iteration need 
to stop" work in parallel?

Short answer: forEachUntilCancelled is not what you think it is.  There 
is not a stream primitive for what you want at this time.

On 3/24/2013 9:29 AM, Mrityunjay Sharma wrote:
> Hi All,
> I was trying to use Stream.forEachUntilCancelled which takes a Consumer and
> a BooleanSupplier as input parameter, as at any point of time this method
> can cancel the iteration and return the control. I thought this would work
> more like while-do statement, so that i can pass the
> condition(BooleanSupplier) where the iteration needs to stop.
> But as BooleanSupplier.getAsBoolean does not take any input parameter, then
> how can we pass a condition where the iteration needs to stop. Is my
> understanding correct or i am interpreting the method implementation
> incorrectly.
> *PS: An implementation Example will be highly appreciated.*
> Thanks & Regards,
> MJ

More information about the lambda-dev mailing list