In this case take_while
is probably ok. The more general issue with it though is timeliness - the stream won’t actually terminate until take_while
yields false, which is the iteration after when you want the stream to end. And that last iteration may not come for a while (if at all). Tokio - stop listening for new tcp connections conditionally is another case of wanting to terminate the stream ASAP.