Skip to content

Commit

Permalink
2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed May 19, 2018
1 parent 4cfee33 commit 9fd798d
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ npm install --save bottleneck
Most APIs have a rate limit. For example, the reddit.com API limits scripts to 1 request every 2 seconds.

```js
const Bottleneck = require("bottleneck");
import Bottleneck from "bottleneck"

// Never more than 1 request running at a time.
// Wait at least 2000ms between each request.
Expand Down
14 changes: 4 additions & 10 deletions bottleneck.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
var cb, ref, returned;
ref = args, (_ref9 = ref, _ref10 = _toArray(_ref9), args = _ref10.slice(0), _ref9), (_splice$call5 = splice.call(args, -1), _splice$call6 = _slicedToArray(_splice$call5, 1), cb = _splice$call6[0], _splice$call5);
returned = task.apply({}, args);
if (returned.then == null) {
return cb(new Bottleneck.prototype.BottleneckError(`The function given to \`schedule()\` did not return a Promise. You may need to return \`Promise.resolve(data)\`. You returned: ${returned} (${typeof returned})`));
}
return returned.then(function (...args) {
return (!((returned != null ? returned.then : void 0) != null && typeof returned.then === "function") ? Promise.resolve(returned) : returned).then(function (...args) {
return cb.apply({}, Array.prototype.concat(null, args));
}).catch(function (...args) {
return cb.apply({}, args);
Expand Down Expand Up @@ -1055,14 +1052,11 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a

RedisStorage = class RedisStorage {
constructor(instance, initSettings, options) {
var r, redis;
var redis;
this.loadAll = this.loadAll.bind(this);
this.instance = instance;
this.initSettings = initSettings;
r = require;
redis = r(function () {
return ["r", "e", "d", "i", "s"].join(""); // Obfuscated or else Webpack/Angular will try to inline the optional redis module
}());
redis = eval("require")("redis"); // Obfuscated or else Webpack/Angular will try to inline the optional redis module
this.originalId = this.instance.id;
this.scripts = scriptTemplates(this.originalId);
parser.load(options, options, this);
Expand Down Expand Up @@ -1547,7 +1541,7 @@ module.exports={
},{}],13:[function(require,module,exports){
module.exports={
"name": "bottleneck",
"version": "2.3.0",
"version": "2.3.1",
"description": "Distributed task scheduler and rate limiter",
"main": "lib/index.js",
"typings": "bottleneck.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion bottleneck.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bottleneck",
"main": "bottleneck.js",
"version": "2.3.0",
"version": "2.3.1",
"homepage": "https://github.com/SGrondin/bottleneck",
"authors": [
"SGrondin <github@simongrondin.name>"
Expand Down
5 changes: 1 addition & 4 deletions lib/Bottleneck.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
var cb, ref, returned;
ref = args, (_ref9 = ref, _ref10 = _toArray(_ref9), args = _ref10.slice(0), _ref9), (_splice$call5 = splice.call(args, -1), _splice$call6 = _slicedToArray(_splice$call5, 1), cb = _splice$call6[0], _splice$call5);
returned = task.apply({}, args);
if (returned.then == null) {
return cb(new Bottleneck.prototype.BottleneckError(`The function given to \`schedule()\` did not return a Promise. You may need to return \`Promise.resolve(data)\`. You returned: ${returned} (${typeof returned})`));
}
return returned.then(function (...args) {
return (!((returned != null ? returned.then : void 0) != null && typeof returned.then === "function") ? Promise.resolve(returned) : returned).then(function (...args) {
return cb.apply({}, Array.prototype.concat(null, args));
}).catch(function (...args) {
return cb.apply({}, args);
Expand Down
7 changes: 2 additions & 5 deletions lib/RedisStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,11 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a

RedisStorage = class RedisStorage {
constructor(instance, initSettings, options) {
var r, redis;
var redis;
this.loadAll = this.loadAll.bind(this);
this.instance = instance;
this.initSettings = initSettings;
r = require;
redis = r(function () {
return ["r", "e", "d", "i", "s"].join(""); // Obfuscated or else Webpack/Angular will try to inline the optional redis module
}());
redis = eval("require")("redis"); // Obfuscated or else Webpack/Angular will try to inline the optional redis module
this.originalId = this.instance.id;
this.scripts = scriptTemplates(this.originalId);
parser.load(options, options, this);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bottleneck",
"version": "2.3.0",
"version": "2.3.1",
"description": "Distributed task scheduler and rate limiter",
"main": "lib/index.js",
"typings": "bottleneck.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/Bottleneck.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ class Bottleneck
options = parser.load options, @jobDefaults
wrapped = (args..., cb) ->
returned = task.apply {}, args
unless returned.then? then return cb new Bottleneck::BottleneckError "The function given to `schedule()` did not return a Promise. You may need to return `Promise.resolve(data)`. You returned: #{returned} (#{typeof returned})"
returned
(unless returned?.then? && typeof returned.then == "function" then Promise.resolve(returned) else returned)
.then (args...) -> cb.apply {}, Array::concat null, args
.catch (args...) -> cb.apply {}, args
new @Promise (resolve, reject) =>
Expand Down
3 changes: 1 addition & 2 deletions src/RedisStorage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ scriptTemplates = (id) ->

class RedisStorage
constructor: (@instance, @initSettings, options) ->
r = require
redis = r do -> ["r", "e", "d", "i", "s"].join("") # Obfuscated or else Webpack/Angular will try to inline the optional redis module
redis = eval("require")("redis") # Obfuscated or else Webpack/Angular will try to inline the optional redis module
@originalId = @instance.id
@scripts = scriptTemplates @originalId
parser.load options, options, @
Expand Down
12 changes: 6 additions & 6 deletions test/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ describe('Promises', function () {
})
})

it('Should not allow non-Promise returns', function (done) {
it('Should allow non-Promise returns', function () {
c = makeTest()
var str = 'This is a string'

c.limiter.ready()
return c.limiter.ready()
.then(function () {
return c.limiter.schedule(() => 'This is a string')
return c.limiter.schedule(() => str)
})
.catch(function (err) {
c.mustEqual(err.message, 'The function given to `schedule()` did not return a Promise. You may need to return `Promise.resolve(data)`. You returned: This is a string (string)')
done()
.then(function (x) {
c.mustEqual(x, str)
})
})

Expand Down

0 comments on commit 9fd798d

Please sign in to comment.