@common.js/p-throttle 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/index.d.ts +117 -0
- package/index.js +397 -0
- package/license +9 -0
- package/package.json +35 -0
package/README.md
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export class AbortError extends Error {
|
|
2
|
+
readonly name: 'AbortError';
|
|
3
|
+
|
|
4
|
+
private constructor();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type AnyFunction = (...arguments_: readonly any[]) => unknown;
|
|
8
|
+
|
|
9
|
+
export type ThrottledFunction<F extends AnyFunction> = F & {
|
|
10
|
+
/**
|
|
11
|
+
Whether future function calls should be throttled or count towards throttling thresholds.
|
|
12
|
+
|
|
13
|
+
@default true
|
|
14
|
+
*/
|
|
15
|
+
isEnabled: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
The number of queued items waiting to be executed.
|
|
19
|
+
*/
|
|
20
|
+
readonly queueSize: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
Abort pending executions. All unresolved promises are rejected with a `pThrottle.AbortError` error.
|
|
24
|
+
*/
|
|
25
|
+
abort(): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type Options = {
|
|
29
|
+
/**
|
|
30
|
+
The maximum number of calls within an `interval`.
|
|
31
|
+
*/
|
|
32
|
+
readonly limit: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
The timespan for `limit` in milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
readonly interval: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
Use a strict, more resource intensive, throttling algorithm. The default algorithm uses a windowed approach that will work correctly in most cases, limiting the total number of calls at the specified limit per interval window. The strict algorithm throttles each call individually, ensuring the limit is not exceeded for any interval.
|
|
41
|
+
|
|
42
|
+
@default false
|
|
43
|
+
*/
|
|
44
|
+
readonly strict?: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
Get notified when function calls are delayed due to exceeding the `limit` of allowed calls within the given `interval`.
|
|
48
|
+
|
|
49
|
+
Can be useful for monitoring the throttling efficiency.
|
|
50
|
+
|
|
51
|
+
@example
|
|
52
|
+
```
|
|
53
|
+
import pThrottle from 'p-throttle';
|
|
54
|
+
|
|
55
|
+
const throttle = pThrottle({
|
|
56
|
+
limit: 2,
|
|
57
|
+
interval: 1000,
|
|
58
|
+
onDelay: () => {
|
|
59
|
+
console.log('Reached interval limit, call is delayed');
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const throttled = throttle(() => {
|
|
64
|
+
console.log('Executing...');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await throttled();
|
|
68
|
+
await throttled();
|
|
69
|
+
await throttled();
|
|
70
|
+
//=> Executing...
|
|
71
|
+
//=> Executing...
|
|
72
|
+
//=> Reached interval limit, call is delayed
|
|
73
|
+
//=> Executing...
|
|
74
|
+
```
|
|
75
|
+
*/
|
|
76
|
+
readonly onDelay?: () => void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
Throttle promise-returning/async/normal functions.
|
|
81
|
+
|
|
82
|
+
It rate-limits function calls without discarding them, making it ideal for external API interactions where avoiding call loss is crucial.
|
|
83
|
+
|
|
84
|
+
@returns A throttle function.
|
|
85
|
+
|
|
86
|
+
Both the `limit` and `interval` options must be specified.
|
|
87
|
+
|
|
88
|
+
@example
|
|
89
|
+
```
|
|
90
|
+
import pThrottle from 'p-throttle';
|
|
91
|
+
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
|
|
94
|
+
const throttle = pThrottle({
|
|
95
|
+
limit: 2,
|
|
96
|
+
interval: 1000
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const throttled = throttle(async index => {
|
|
100
|
+
const secDiff = ((Date.now() - now) / 1000).toFixed();
|
|
101
|
+
return `${index}: ${secDiff}s`;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
for (let index = 1; index <= 6; index++) {
|
|
105
|
+
(async () => {
|
|
106
|
+
console.log(await throttled(index));
|
|
107
|
+
})();
|
|
108
|
+
}
|
|
109
|
+
//=> 1: 0s
|
|
110
|
+
//=> 2: 0s
|
|
111
|
+
//=> 3: 1s
|
|
112
|
+
//=> 4: 1s
|
|
113
|
+
//=> 5: 2s
|
|
114
|
+
//=> 6: 2s
|
|
115
|
+
```
|
|
116
|
+
*/
|
|
117
|
+
export default function pThrottle(options: Options): <F extends AnyFunction>(function_: F) => ThrottledFunction<F>;
|
package/index.js
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
AbortError: function() {
|
|
13
|
+
return AbortError;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return pThrottle;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function _assertThisInitialized(self) {
|
|
20
|
+
if (self === void 0) {
|
|
21
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
22
|
+
}
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
26
|
+
try {
|
|
27
|
+
var info = gen[key](arg);
|
|
28
|
+
var value = info.value;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (info.done) {
|
|
34
|
+
resolve(value);
|
|
35
|
+
} else {
|
|
36
|
+
Promise.resolve(value).then(_next, _throw);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _asyncToGenerator(fn) {
|
|
40
|
+
return function() {
|
|
41
|
+
var self = this, args = arguments;
|
|
42
|
+
return new Promise(function(resolve, reject) {
|
|
43
|
+
var gen = fn.apply(self, args);
|
|
44
|
+
function _next(value) {
|
|
45
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
46
|
+
}
|
|
47
|
+
function _throw(err) {
|
|
48
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
49
|
+
}
|
|
50
|
+
_next(undefined);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function _classCallCheck(instance, Constructor) {
|
|
55
|
+
if (!(instance instanceof Constructor)) {
|
|
56
|
+
throw new TypeError("Cannot call a class as a function");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function isNativeReflectConstruct() {
|
|
60
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
61
|
+
if (Reflect.construct.sham) return false;
|
|
62
|
+
if (typeof Proxy === "function") return true;
|
|
63
|
+
try {
|
|
64
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
|
65
|
+
return true;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _construct(Parent, args, Class) {
|
|
71
|
+
if (isNativeReflectConstruct()) {
|
|
72
|
+
_construct = Reflect.construct;
|
|
73
|
+
} else {
|
|
74
|
+
_construct = function _construct(Parent, args, Class) {
|
|
75
|
+
var a = [
|
|
76
|
+
null
|
|
77
|
+
];
|
|
78
|
+
a.push.apply(a, args);
|
|
79
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
80
|
+
var instance = new Constructor();
|
|
81
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
82
|
+
return instance;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return _construct.apply(null, arguments);
|
|
86
|
+
}
|
|
87
|
+
function _getPrototypeOf(o) {
|
|
88
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
89
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
90
|
+
};
|
|
91
|
+
return _getPrototypeOf(o);
|
|
92
|
+
}
|
|
93
|
+
function _inherits(subClass, superClass) {
|
|
94
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
95
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
96
|
+
}
|
|
97
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
98
|
+
constructor: {
|
|
99
|
+
value: subClass,
|
|
100
|
+
writable: true,
|
|
101
|
+
configurable: true
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
105
|
+
}
|
|
106
|
+
function _isNativeFunction(fn) {
|
|
107
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
108
|
+
}
|
|
109
|
+
function _possibleConstructorReturn(self, call) {
|
|
110
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
111
|
+
return call;
|
|
112
|
+
}
|
|
113
|
+
return _assertThisInitialized(self);
|
|
114
|
+
}
|
|
115
|
+
function _setPrototypeOf(o, p) {
|
|
116
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
117
|
+
o.__proto__ = p;
|
|
118
|
+
return o;
|
|
119
|
+
};
|
|
120
|
+
return _setPrototypeOf(o, p);
|
|
121
|
+
}
|
|
122
|
+
var _typeof = function(obj) {
|
|
123
|
+
"@swc/helpers - typeof";
|
|
124
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
125
|
+
};
|
|
126
|
+
function _wrapNativeSuper(Class) {
|
|
127
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
128
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
129
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
130
|
+
if (typeof Class !== "function") {
|
|
131
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
132
|
+
}
|
|
133
|
+
if (typeof _cache !== "undefined") {
|
|
134
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
135
|
+
_cache.set(Class, Wrapper);
|
|
136
|
+
}
|
|
137
|
+
function Wrapper() {
|
|
138
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
139
|
+
}
|
|
140
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
141
|
+
constructor: {
|
|
142
|
+
value: Wrapper,
|
|
143
|
+
enumerable: false,
|
|
144
|
+
writable: true,
|
|
145
|
+
configurable: true
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
149
|
+
};
|
|
150
|
+
return _wrapNativeSuper(Class);
|
|
151
|
+
}
|
|
152
|
+
function _isNativeReflectConstruct() {
|
|
153
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
154
|
+
if (Reflect.construct.sham) return false;
|
|
155
|
+
if (typeof Proxy === "function") return true;
|
|
156
|
+
try {
|
|
157
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
158
|
+
return true;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function _createSuper(Derived) {
|
|
164
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
165
|
+
return function _createSuperInternal() {
|
|
166
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
167
|
+
if (hasNativeReflectConstruct) {
|
|
168
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
169
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
170
|
+
} else {
|
|
171
|
+
result = Super.apply(this, arguments);
|
|
172
|
+
}
|
|
173
|
+
return _possibleConstructorReturn(this, result);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
177
|
+
var f, y, t, g, _ = {
|
|
178
|
+
label: 0,
|
|
179
|
+
sent: function() {
|
|
180
|
+
if (t[0] & 1) throw t[1];
|
|
181
|
+
return t[1];
|
|
182
|
+
},
|
|
183
|
+
trys: [],
|
|
184
|
+
ops: []
|
|
185
|
+
};
|
|
186
|
+
return g = {
|
|
187
|
+
next: verb(0),
|
|
188
|
+
"throw": verb(1),
|
|
189
|
+
"return": verb(2)
|
|
190
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
191
|
+
return this;
|
|
192
|
+
}), g;
|
|
193
|
+
function verb(n) {
|
|
194
|
+
return function(v) {
|
|
195
|
+
return step([
|
|
196
|
+
n,
|
|
197
|
+
v
|
|
198
|
+
]);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function step(op) {
|
|
202
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
203
|
+
while(_)try {
|
|
204
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
205
|
+
if (y = 0, t) op = [
|
|
206
|
+
op[0] & 2,
|
|
207
|
+
t.value
|
|
208
|
+
];
|
|
209
|
+
switch(op[0]){
|
|
210
|
+
case 0:
|
|
211
|
+
case 1:
|
|
212
|
+
t = op;
|
|
213
|
+
break;
|
|
214
|
+
case 4:
|
|
215
|
+
_.label++;
|
|
216
|
+
return {
|
|
217
|
+
value: op[1],
|
|
218
|
+
done: false
|
|
219
|
+
};
|
|
220
|
+
case 5:
|
|
221
|
+
_.label++;
|
|
222
|
+
y = op[1];
|
|
223
|
+
op = [
|
|
224
|
+
0
|
|
225
|
+
];
|
|
226
|
+
continue;
|
|
227
|
+
case 7:
|
|
228
|
+
op = _.ops.pop();
|
|
229
|
+
_.trys.pop();
|
|
230
|
+
continue;
|
|
231
|
+
default:
|
|
232
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
233
|
+
_ = 0;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
237
|
+
_.label = op[1];
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
241
|
+
_.label = t[1];
|
|
242
|
+
t = op;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
if (t && _.label < t[2]) {
|
|
246
|
+
_.label = t[2];
|
|
247
|
+
_.ops.push(op);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
if (t[2]) _.ops.pop();
|
|
251
|
+
_.trys.pop();
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
op = body.call(thisArg, _);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
op = [
|
|
257
|
+
6,
|
|
258
|
+
e
|
|
259
|
+
];
|
|
260
|
+
y = 0;
|
|
261
|
+
} finally{
|
|
262
|
+
f = t = 0;
|
|
263
|
+
}
|
|
264
|
+
if (op[0] & 5) throw op[1];
|
|
265
|
+
return {
|
|
266
|
+
value: op[0] ? op[1] : void 0,
|
|
267
|
+
done: true
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
var AbortError = /*#__PURE__*/ function(Error1) {
|
|
272
|
+
"use strict";
|
|
273
|
+
_inherits(AbortError, Error1);
|
|
274
|
+
var _super = _createSuper(AbortError);
|
|
275
|
+
function AbortError() {
|
|
276
|
+
_classCallCheck(this, AbortError);
|
|
277
|
+
var _this;
|
|
278
|
+
_this = _super.call(this, "Throttled function aborted");
|
|
279
|
+
_this.name = "AbortError";
|
|
280
|
+
return _this;
|
|
281
|
+
}
|
|
282
|
+
return AbortError;
|
|
283
|
+
}(_wrapNativeSuper(Error));
|
|
284
|
+
function pThrottle(param) {
|
|
285
|
+
var limit = param.limit, interval = param.interval, strict = param.strict, onDelay = param.onDelay;
|
|
286
|
+
var windowedDelay = function windowedDelay() {
|
|
287
|
+
var now = Date.now();
|
|
288
|
+
if (now - currentTick > interval) {
|
|
289
|
+
activeCount = 1;
|
|
290
|
+
currentTick = now;
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
if (activeCount < limit) {
|
|
294
|
+
activeCount++;
|
|
295
|
+
} else {
|
|
296
|
+
currentTick += interval;
|
|
297
|
+
activeCount = 1;
|
|
298
|
+
}
|
|
299
|
+
return currentTick - now;
|
|
300
|
+
};
|
|
301
|
+
var strictDelay = function strictDelay() {
|
|
302
|
+
var now = Date.now();
|
|
303
|
+
// Clear the queue if there's a significant delay since the last execution
|
|
304
|
+
if (strictTicks.length > 0 && now - strictTicks.at(-1) > interval) {
|
|
305
|
+
strictTicks.length = 0;
|
|
306
|
+
}
|
|
307
|
+
// If the queue is not full, add the current time and execute immediately
|
|
308
|
+
if (strictTicks.length < limit) {
|
|
309
|
+
strictTicks.push(now);
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
// Calculate the next execution time based on the first item in the queue
|
|
313
|
+
var nextExecutionTime = strictTicks[0] + interval;
|
|
314
|
+
// Shift the queue and add the new execution time
|
|
315
|
+
strictTicks.shift();
|
|
316
|
+
strictTicks.push(nextExecutionTime);
|
|
317
|
+
// Calculate the delay for the current execution
|
|
318
|
+
return Math.max(0, nextExecutionTime - now);
|
|
319
|
+
};
|
|
320
|
+
if (!Number.isFinite(limit)) {
|
|
321
|
+
throw new TypeError("Expected `limit` to be a finite number");
|
|
322
|
+
}
|
|
323
|
+
if (!Number.isFinite(interval)) {
|
|
324
|
+
throw new TypeError("Expected `interval` to be a finite number");
|
|
325
|
+
}
|
|
326
|
+
var queue = new Map();
|
|
327
|
+
var currentTick = 0;
|
|
328
|
+
var activeCount = 0;
|
|
329
|
+
var strictTicks = [];
|
|
330
|
+
var getDelay = strict ? strictDelay : windowedDelay;
|
|
331
|
+
return function(function_) {
|
|
332
|
+
var throttled = function() {
|
|
333
|
+
for(var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++){
|
|
334
|
+
arguments_[_key] = arguments[_key];
|
|
335
|
+
}
|
|
336
|
+
var _this = this;
|
|
337
|
+
if (!throttled.isEnabled) {
|
|
338
|
+
var _this1 = this;
|
|
339
|
+
return _asyncToGenerator(function() {
|
|
340
|
+
return __generator(this, function(_state) {
|
|
341
|
+
return [
|
|
342
|
+
2,
|
|
343
|
+
function_.apply(_this1, arguments_)
|
|
344
|
+
];
|
|
345
|
+
});
|
|
346
|
+
})();
|
|
347
|
+
}
|
|
348
|
+
var timeoutId;
|
|
349
|
+
return new Promise(function(resolve, reject) {
|
|
350
|
+
var execute = function() {
|
|
351
|
+
resolve(function_.apply(_this, arguments_));
|
|
352
|
+
queue.delete(timeoutId);
|
|
353
|
+
};
|
|
354
|
+
var delay = getDelay();
|
|
355
|
+
if (delay > 0) {
|
|
356
|
+
timeoutId = setTimeout(execute, delay);
|
|
357
|
+
queue.set(timeoutId, reject);
|
|
358
|
+
onDelay === null || onDelay === void 0 ? void 0 : onDelay();
|
|
359
|
+
} else {
|
|
360
|
+
execute();
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
throttled.abort = function() {
|
|
365
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
366
|
+
try {
|
|
367
|
+
for(var _iterator = queue.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
368
|
+
var timeout = _step.value;
|
|
369
|
+
clearTimeout(timeout);
|
|
370
|
+
queue.get(timeout)(new AbortError());
|
|
371
|
+
}
|
|
372
|
+
} catch (err) {
|
|
373
|
+
_didIteratorError = true;
|
|
374
|
+
_iteratorError = err;
|
|
375
|
+
} finally{
|
|
376
|
+
try {
|
|
377
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
378
|
+
_iterator.return();
|
|
379
|
+
}
|
|
380
|
+
} finally{
|
|
381
|
+
if (_didIteratorError) {
|
|
382
|
+
throw _iteratorError;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
queue.clear();
|
|
387
|
+
strictTicks.splice(0, strictTicks.length);
|
|
388
|
+
};
|
|
389
|
+
throttled.isEnabled = true;
|
|
390
|
+
Object.defineProperty(throttled, "queueSize", {
|
|
391
|
+
get: function get() {
|
|
392
|
+
return queue.size;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return throttled;
|
|
396
|
+
};
|
|
397
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@common.js/p-throttle",
|
|
3
|
+
"version": "6.1.0",
|
|
4
|
+
"description": "p-throttle package exported as CommonJS modules",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "etienne-martin/common.js",
|
|
7
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
+
"type": "commonjs",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "xo && ava && tsd"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"index.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"ava": "^5.3.1",
|
|
22
|
+
"delay": "^6.0.0",
|
|
23
|
+
"in-range": "^3.0.0",
|
|
24
|
+
"time-span": "^5.1.0",
|
|
25
|
+
"tsd": "^0.29.0",
|
|
26
|
+
"xo": "^0.56.0"
|
|
27
|
+
},
|
|
28
|
+
"ava": {
|
|
29
|
+
"serial": true
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
32
|
+
"dependencies": {},
|
|
33
|
+
"types": "./index.d.ts",
|
|
34
|
+
"main": "./index.js"
|
|
35
|
+
}
|