Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple callbacks #987

Closed
franciscop opened this issue Dec 23, 2015 · 1 comment
Closed

Allow for multiple callbacks #987

franciscop opened this issue Dec 23, 2015 · 1 comment

Comments

@franciscop
Copy link

I created water-pipe [alpha] based on waterfall. However I have seen several issues ( #815, #559, #535 ) related to stopping people from calling multiple times the callback, however I'm opening one to keep allowing this:

// One of the tasks as an example
function(data, callback){
  callback(null, 'first');
  setTimeout(callback.bind(false, 'second'), 10000);
}

In this way we allow the waterfall to "branch", so it can follow two different ways at the same time. This is useful in many situations, for example when crawling a site and we want to check later without DDOS'ing someone if a link is already up (above example).

In this way the next task is executed for both branches, which is desirable for this kind of situations. Also it'd be desirable if the last callback was also executed several times, one per branch.

If we remove this feature as suggested in some issues, is there any option to make this to work? Or should I work from the current codebase (without jumping to 2.x)?

From my point of view, if a user calls a callback two times, it should just be called two times, as in any normal function. It just happens that this callbacks keeps some state going on.

@franciscop franciscop changed the title Allow for multiple callbacks in waterfall Allow for multiple callbacks Dec 23, 2015
@aearly
Copy link
Collaborator

aearly commented Jan 2, 2016

We've been trying to standardize functions async works with as functions that call their callback exactly once. Calling a callback more than once is often a source of bugs for many people -- we want to guard against it.

If you want to call a callback multiple times, what you're describing sounds more like a stream. The use of the term pipe also completes the picture. There are also FRP-style libraries like RxJS and BaconJs (and Highlander) that make working with streams really easy -- they have a similar feel to your water-pipe helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants