then / promise

Bare bones Promises/A+ implementation
https://www.promisejs.org
MIT License
2.58k stars 312 forks source link

Wrong order of parameters in example #140

Closed hefekranz closed 7 years ago

hefekranz commented 7 years ago

Not a biggie, but it can be frustrating for noobs.

In the Promise examples in the readme:

var Promise = require('promise');

var promise = new Promise(function (resolve, reject) {
  get('http://www.google.com', function (err, res) {
    if (err) reject(err);
    else resolve(res);
  });
});

"err" and "res" have the wrong order, thus rejecting the correct response. If this is referring to nodes http.get at least.

Not sure though, I'm a noob myself :)

Cheers and thank you for your work.

edef1c commented 7 years ago

Node's http.get callback doesn't take an error — anything that does is an error-first callback in node.

For http.get:

var Promise = require('promise');
var http = require('http')

var promise = new Promise(function (resolve, reject) {
  http.get('http://www.google.com', resolve).on('error', reject)
});

Cheers and thank you for your work.

Thanks ❤️