diff --git a/index.js b/index.js index a1d1cd7..b182a10 100644 --- a/index.js +++ b/index.js @@ -128,26 +128,20 @@ function asCallback(opts, cb) { } function asPromise(opts) { - var resolve, reject; + var promise = new pinkiePromise(function (resolve, reject) { + asCallback(opts, function (err, data, response) { + response.body = data; - var promise = new pinkiePromise(function (_resolve, _reject) { - resolve = _resolve; - reject = _reject; - }); - - var cb = function (err, data, response) { - response.body = data; - - if (err) { - err.response = response; - reject(err); - return; - } + if (err) { + err.response = response; + reject(err); + return; + } - resolve(response); - }; + resolve(response); + }); + }); - asCallback(opts, cb); return promise; } @@ -203,9 +197,7 @@ function normalizeArguments(url, opts) { } opts = objectAssign( - { - protocol: 'http:' - }, + {protocol: 'http:'}, typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url, opts ); @@ -261,7 +253,8 @@ function got(url, opts, cb) { opts = normalizeArguments(url, opts); if (cb) { - return asCallback(opts, cb); + asCallback(opts, cb); + return; } return asPromise(opts); diff --git a/package.json b/package.json index 46e1fac..7570a97 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "tap test/test-*.js", - "coverage": "istanbul cover tape --report html -- test/test-*.js" + "test": "tap test/test-*.js" }, "files": [ "index.js" diff --git a/readme.md b/readme.md index 65b6cb5..41803a3 100644 --- a/readme.md +++ b/readme.md @@ -186,16 +186,16 @@ got('todomvc.com', { ``` -## Node 0.10 +## Node 0.10.x -It is a known issue with Node [http.Agent](https://nodejs.org/docs/v0.10.39/api/http.html#http_class_http_agent) and `agent.maxSockets`, which is set to `5`. This can cause low performance of application and (in rare cases) deadlocks. To avoid this you can set it manually: +It is a known issue with old good Node 0.10.x [http.Agent](https://nodejs.org/docs/v0.10.39/api/http.html#http_class_http_agent) and `agent.maxSockets`, which is set to `5`. This can cause low performance of application and (in rare cases) deadlocks. To avoid this you can set it manually: ```js require('http').globalAgent.maxSockets = Infinity; require('https').globalAgent.maxSockets = Infinity; ``` -This should only ever be done at the top-level application layer. +This should only ever be done if you have Node version 0.10.x and at the top-level application layer. ## Related