Socket
Socket
Sign inDemoInstall

@scoir/async-throttler

Package Overview
Dependencies
0
Maintainers
27
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 3.0.0-beta.ed162590

dist/index.spec.js

120

dist/index.js

@@ -1,84 +0,48 @@

"use strict";
class Throttler {
constructor(cb) {
this.cb = cb;
this.cb({
isProcessing: false,
isProcessed: false,
isComplete: false,
isError: false
});
}
Object.defineProperty(exports, "__esModule", {
value: true
});
execute(promise, delay = 700) {
this.cb({
isProcessing: true,
isProcessed: false,
isComplete: false,
isError: false
}); // NOTE: this is exposed only for testing and should not be used outside of that context
var _promise = require("babel-runtime/core-js/promise");
this._executedPromise = Promise.all([promise, new Promise(resolve => setTimeout(resolve, delay))]).then(() => this.cb({
isProcessing: false,
isProcessed: true,
isComplete: true,
isError: false
})).catch(() => this.cb({
isProcessing: false,
isProcessed: false,
isComplete: true,
isError: true
}));
}
var _promise2 = _interopRequireDefault(_promise);
reset() {
this.cb({
isProcessing: false,
isProcessed: false,
isComplete: false,
isError: false
});
}
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
}
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require("babel-runtime/helpers/createClass");
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Throttler = function () {
function Throttler(cb) {
(0, _classCallCheck3.default)(this, Throttler);
this.cb = cb;
this.cb({
isProcessing: false,
isProcessed: false,
isComplete: false,
isError: false
});
}
(0, _createClass3.default)(Throttler, [{
key: "execute",
value: function execute(promise) {
var _this = this;
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 700;
this.cb({
isProcessing: true,
isProcessed: false,
isComplete: false,
isError: false
});
// NOTE: this is exposed only for testing and should not be used outside of that context
this._executedPromise = _promise2.default.all([promise, new _promise2.default(function (resolve) {
return setTimeout(resolve, delay);
})]).then(function () {
return _this.cb({
isProcessing: false,
isProcessed: true,
isComplete: true,
isError: false
});
}).catch(function () {
return _this.cb({
isProcessing: false,
isProcessed: false,
isComplete: true,
isError: true
});
});
}
}, {
key: "reset",
value: function reset() {
this.cb({
isProcessing: false,
isProcessed: false,
isComplete: false,
isError: false
});
}
}]);
return Throttler;
}();
exports.default = {
create: function create(cb) {
return new Throttler(cb);
}
export default {
create: cb => {
return new Throttler(cb);
}
};

@@ -1,6 +0,3 @@

import bluebird from 'bluebird';
import throttler from './index';
it('should create a throttler', () => {

@@ -29,3 +26,3 @@ const cb = jest.fn();

it('should allow promise execution', async () => {
const promise = bluebird.resolve();
const promise = Promise.resolve();
inst.execute(promise)

@@ -45,3 +42,3 @@ expect(cb).toHaveBeenCalledWith({

jest.runTimersToTime(700);
jest.advanceTimersByTime(700);

@@ -64,3 +61,3 @@ await inst._executedPromise;

jest.runTimersToTime(700);
jest.advanceTimersByTime(700);

@@ -67,0 +64,0 @@ await inst._executedPromise;

{
"name": "@scoir/async-throttler",
"version": "2.0.1",
"version": "3.0.0-beta.ed162590",
"description": "",

@@ -5,0 +5,0 @@ "author": "@scoir",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc