Sounds like you want a pull stream to me. You pull from the data until you dont need it anymore and then stop pulling.
Which can be contrasted to a push stream which will continue pushing at you forcing you to do an if check and just ignore the excess data. So I think the issue is your trying to pull from a push stream in your API and it's hard. Try making the input of whatever your doing a pull stream instead. On Mon, Jan 7, 2013 at 7:47 AM, Bradley Meck <[email protected]> wrote: > Anyone have a sane and performant way that they break out of a domain or > action such as middleware? I am trying to design such behavior but am faced > with a multitude of interesting issues. The classic example of this problem > can be seen with Array.prototype.forEach (though this has the easier > synchronous execution for breaking): > > ```javascript > // we only want to print first 2 items > [1, 2, 3].forEach(function (item) { > if (item > 2) { > return; > } > console.log(item); > }); > ``` > > We often see the error first callback cause a fast fail on waterfall style > control flow, but what if we are not issuing an error, but rather a > terminating condition (making all middleware after it ignored)? Right now > my only solution is to add another callback to arguments ala: > > ```javascript > function finish(creds, finish, next) { > if (creds == 'secret') finish(null, 'user/mary'); > else next(null, creds); > } > actor.perform('auth', creds, finish, next); > ``` > > This seems, a bit... overkill to type out though. Anyways, looking for > suggestions. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
