caolan / highland

High-level streams library for Node.js and the browser
https://caolan.github.io/highland
Apache License 2.0
3.43k stars 147 forks source link

End stream within map() #513

Open bradserbu opened 8 years ago

bradserbu commented 8 years ago

How can I force a stream to end from within a map() function?

Scenario:

vqvu commented 8 years ago

Implement a custom consume handler that checks for QUERY_LIMIT_MESSAGE and pushes nil.

stream.map($(promise))
    .merge()
    .consume((err, x, push, next) => {
        if (x === _.nil || x === QUERY_LIMIT_MESSAGE) {
            push(null, _.nil);
        } else{
            push(err, x);
            next();
        }
    })
bradserbu commented 8 years ago

Would this propagate the .end() back to the source stream?