@jcoreio/async-throttle
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -62,5 +62,3 @@ "use strict"; | ||
nextArgs = null; | ||
const result = (async () => await fn(...args))(); | ||
const result = Promise.resolve(fn(...args)); | ||
lastInvocationDone = result.catch(() => {}).then(() => { | ||
@@ -74,3 +72,8 @@ lastInvocationDone = null; | ||
function wrapper(...args) { | ||
nextArgs = nextArgs ? getNextArgs(nextArgs, args) : args; | ||
try { | ||
nextArgs = nextArgs ? getNextArgs(nextArgs, args) : args; | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
if (!nextArgs) return Promise.reject(new Error('unexpected error: nextArgs is null')); | ||
@@ -77,0 +80,0 @@ if (nextInvocation) return nextInvocation; |
58
index.js
@@ -7,6 +7,6 @@ "use strict"; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
@@ -112,20 +112,3 @@ | ||
nextArgs = null; | ||
var result = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return fn.apply(void 0, (0, _toConsumableArray2["default"])(args)); | ||
case 2: | ||
return _context.abrupt("return", _context.sent); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))(); | ||
var result = Promise.resolve(fn.apply(void 0, (0, _toConsumableArray2["default"])(args))); | ||
lastInvocationDone = result["catch"](function () {}).then(function () { | ||
@@ -139,7 +122,12 @@ lastInvocationDone = null; | ||
function wrapper() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
try { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
nextArgs = nextArgs ? getNextArgs(nextArgs, args) : args; | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
nextArgs = nextArgs ? getNextArgs(nextArgs, args) : args; | ||
if (!nextArgs) return Promise.reject(new Error('unexpected error: nextArgs is null')); | ||
@@ -150,9 +138,9 @@ if (nextInvocation) return nextInvocation; | ||
wrapper.cancel = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { | ||
wrapper.cancel = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var _delay, _delay$cancel; | ||
var prevLastInvocationDone; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
@@ -165,3 +153,3 @@ prevLastInvocationDone = lastInvocationDone; | ||
delay = null; | ||
_context2.next = 8; | ||
_context.next = 8; | ||
return prevLastInvocationDone; | ||
@@ -171,16 +159,16 @@ | ||
case "end": | ||
return _context2.stop(); | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee); | ||
})); | ||
wrapper.flush = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() { | ||
wrapper.flush = /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { | ||
var _delay2, _delay2$flush; | ||
return _regenerator["default"].wrap(function _callee3$(_context3) { | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
(_delay2 = delay) === null || _delay2 === void 0 ? void 0 : (_delay2$flush = _delay2.flush) === null || _delay2$flush === void 0 ? void 0 : _delay2$flush.call(_delay2); | ||
_context3.next = 3; | ||
_context2.next = 3; | ||
return lastInvocationDone; | ||
@@ -190,6 +178,6 @@ | ||
case "end": | ||
return _context3.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
}, _callee2); | ||
})); | ||
@@ -196,0 +184,0 @@ return wrapper; |
{ | ||
"name": "@jcoreio/async-throttle", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"description": "throttle async and promise-returning functions. Other packages don't do it right.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25142
254