🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

interval-queue

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interval-queue - npm Package Compare versions

Comparing version
1.0.1
to
1.0.3
+4
README.md
# interval-queue
+35
-3

@@ -11,6 +11,10 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.clearIntervals = exports.createInterval = void 0;
exports.clearIntervals = exports.deleteInterval = exports.deleteIntervals = exports.createIntervalHour = exports.createIntervalMinute = exports.createIntervalSecond = exports.createInterval = void 0;
const loops = [];
const createInterval = (time, fn) => {
const loop = setInterval(fn, time);
const createInterval = (fn, time, ...args) => {
const loop = setInterval((...args) => {
const out = fn(...args);
if (out === false)
clearInterval(loop);
}, time, ...args);
loops.push(loop);

@@ -20,2 +24,30 @@ return loop;

exports.createInterval = createInterval;
const createIntervalSecond = (fn, time, ...args) => (0, exports.createInterval)(fn, time * 1000, ...args);
exports.createIntervalSecond = createIntervalSecond;
const createIntervalMinute = (fn, time, ...args) => (0, exports.createIntervalSecond)(fn, time * 60, ...args);
exports.createIntervalMinute = createIntervalMinute;
const createIntervalHour = (fn, time, ...args) => (0, exports.createIntervalMinute)(fn, time * 60, ...args);
exports.createIntervalHour = createIntervalHour;
const deleteIntervals = (loops) => {
let stopCnt = 0;
for (const loop of loops) {
try {
if ((0, exports.deleteInterval)(loop))
stopCnt++;
}
catch (e) { }
}
return stopCnt;
};
exports.deleteIntervals = deleteIntervals;
const deleteInterval = (loop) => {
if (loops.includes(loop)) {
clearInterval(loop);
loops.splice(loops.indexOf(loop), 1);
return true;
}
else
return false;
};
exports.deleteInterval = deleteInterval;
const clearIntervals = () => {

@@ -22,0 +54,0 @@ loops.forEach(loop => {

@@ -9,3 +9,10 @@ /**

*/
export declare const createInterval: (time: number, fn: () => void) => NodeJS.Timeout;
type TimeoutHandle<TArgs extends any[]> = (...args: TArgs) => void | boolean;
export declare const createInterval: <TArgs extends any[]>(fn: TimeoutHandle<TArgs>, time: number, ...args: TArgs) => NodeJS.Timeout;
export declare const createIntervalSecond: <TArgs extends any[]>(fn: TimeoutHandle<TArgs>, time: number, ...args: TArgs) => NodeJS.Timeout;
export declare const createIntervalMinute: <TArgs extends any[]>(fn: TimeoutHandle<TArgs>, time: number, ...args: TArgs) => NodeJS.Timeout;
export declare const createIntervalHour: <TArgs extends any[]>(fn: TimeoutHandle<TArgs>, time: number, ...args: TArgs) => NodeJS.Timeout;
export declare const deleteIntervals: (loops: NodeJS.Timeout[]) => number;
export declare const deleteInterval: (loop: NodeJS.Timeout) => boolean;
export declare const clearIntervals: () => void;
export {};

@@ -10,7 +10,34 @@ /**

const loops = [];
export const createInterval = (time, fn) => {
const loop = setInterval(fn, time);
export const createInterval = (fn, time, ...args) => {
const loop = setInterval((...args) => {
const out = fn(...args);
if (out === false)
clearInterval(loop);
}, time, ...args);
loops.push(loop);
return loop;
};
export const createIntervalSecond = (fn, time, ...args) => createInterval(fn, time * 1000, ...args);
export const createIntervalMinute = (fn, time, ...args) => createIntervalSecond(fn, time * 60, ...args);
export const createIntervalHour = (fn, time, ...args) => createIntervalMinute(fn, time * 60, ...args);
export const deleteIntervals = (loops) => {
let stopCnt = 0;
for (const loop of loops) {
try {
if (deleteInterval(loop))
stopCnt++;
}
catch (e) { }
}
return stopCnt;
};
export const deleteInterval = (loop) => {
if (loops.includes(loop)) {
clearInterval(loop);
loops.splice(loops.indexOf(loop), 1);
return true;
}
else
return false;
};
export const clearIntervals = () => {

@@ -17,0 +44,0 @@ loops.forEach(loop => {

+1
-1
{
"name": "interval-queue",
"version": "1.0.1",
"version": "1.0.3",
"description": "interval queue",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",