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

More consise task definition or update example #5

Closed
caseyhoward opened this issue Nov 15, 2014 · 1 comment
Closed

More consise task definition or update example #5

caseyhoward opened this issue Nov 15, 2014 · 1 comment

Comments

@caseyhoward
Copy link

I was looking at your example that returns a promise and was wondering why you would return a promise that way.

taker.task('task3', function(){
  return new Promise(function(resolve, reject){
    // do things
    resolve();
  });
});

What's the use case? Wanting to call reject? If so, something like this seems more elegant and also handles the callback use case.

taker.task('task1', function(resolve, reject){
  // do things
  resolve(); // when everything is done
});

However, it still does make sense to support promises if you are using a library that returns promises.

var http = require('some-http-library');

taker.task('task1', function(){
  return http.get('http://github.com'); // returns a promise
});

I just don't understand why you would ever want to define a promise within a task. Not that big of a deal though.

@phated
Copy link
Member

phated commented Nov 16, 2014

I am confused by the question. The example from the README is to show that you can return any promise.

The way a promise is defined is:

new Promise(function(resolve, reject){

});

We aren't going to be passing a resolve and reject function into a task, as we already pass an optional node-style callback into it. The http example you posted is more confusing than showing a newly constructed promise being returned because it is not obvious the library returns promises.

@phated phated closed this as completed Nov 16, 2014
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

2 participants