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

API for breaking stack queue execution #2

Open
cusspvz opened this issue Jan 19, 2015 · 2 comments
Open

API for breaking stack queue execution #2

cusspvz opened this issue Jan 19, 2015 · 2 comments

Comments

@cusspvz
Copy link
Member

cusspvz commented Jan 19, 2015

Currently stack-queue stack queue execution breaking is defined by breakOn method option, which defaults for breaking on String type values.

Would you like to see implemented any other kind of breaking methods or API?

ping @brunocasanova @ajbloureiro @gabrielpconceicao

@mickhansen it would be great if you give your opinion also, since it could be useful also for sequelize. ( related with sequelize/sequelize#2932 )

@cusspvz
Copy link
Member Author

cusspvz commented Jan 19, 2015

On sequelize/sequelize#1852, @mickhansen and me have discussed some approaches to short-circuit sequelize hooks, which are kindly the same i would propose on this issue, but as they don't seem reasonable for me i would like to present whats going into my mind:

API Proposal

// Pass a `control` method with methods on it

// `control` would have to be backwards compatible (for those who use `next`)
// should have the same behavior as `control.continue`
stack.queue(function ( next ) {
  next();
});

// continue to next stack queued method
// Same as old `next`
stack.queue(function ( control ) {
  control.continue();
});

// break queue without a reason
stack.queue(function ( control ) {
  control.break();
});

// break queue fulfilling without a result
stack.queue(function ( control ) {
  control.break.fulfilling();
});

// break queue rejecting without an error
stack.queue(function ( control ) {
  control.break.rejecting();
});

// break queue fulfilling with a result
stack.queue(function ( control ) {
  control.break.fulfilling([
    'some',
    'data'
  ]);
});

// break queue rejecting without an error
stack.queue(function ( control ) {
  control.break.rejecting( new Error( "breaking things, just for fun" ) );
});

@cusspvz
Copy link
Member Author

cusspvz commented Jan 19, 2015

Also, if control variable is defined within function, stack-queue should IGNORE entirely returned values (so it doesn't conflict with returning promises).

We can think about logging a deprecated message when something is returned from a method within stack which is using control variable.

For detecting control parameter i would suggest to use ƒ. ƒ.Function.getParamNames()

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

No branches or pull requests

1 participant