client-run-queue
Advanced tools
Comparing version 1.1.12 to 2.0.0
"use strict"; | ||
/* istanbul ignore file */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setRunAfterInteractions = exports.resetRunAfterInteractions = exports.runAfterInteractions = void 0; | ||
const queue_microtask_1 = __importDefault(require("queue-microtask")); | ||
const defaultRunAfterInteractions = (_id, func) => { | ||
const timeout = setTimeout(func, 0); | ||
let wasCanceled = false; | ||
(0, queue_microtask_1.default)(() => { | ||
if (wasCanceled) { | ||
return; | ||
} | ||
func(); | ||
}); | ||
return () => { | ||
clearTimeout(timeout); | ||
wasCanceled = true; | ||
}; | ||
@@ -10,0 +20,0 @@ }; |
@@ -17,2 +17,3 @@ "use strict"; | ||
const heap_1 = __importDefault(require("heap")); | ||
const queue_microtask_1 = __importDefault(require("queue-microtask")); | ||
const run_after_interactions_1 = require("../config/run-after-interactions"); | ||
@@ -124,2 +125,3 @@ const stats_handler_1 = require("../config/stats-handler"); | ||
this.scheduleAfterDelay = (priority, id, run, options) => { | ||
var _a; | ||
let wasCanceled = false; | ||
@@ -130,3 +132,6 @@ let wasResolved = false; | ||
let delayedEntryNode = undefined; | ||
const timeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () { | ||
const runner = () => __awaiter(this, void 0, void 0, function* () { | ||
if (wasCanceled) { | ||
return; | ||
} | ||
if (delayedEntryNode !== undefined) { | ||
@@ -154,3 +159,5 @@ this.delayedEntries.remove(delayedEntryNode); | ||
} | ||
}), options.delayMSec); | ||
}); | ||
const delayMSec = (_a = options.delayMSec) !== null && _a !== void 0 ? _a : 0; | ||
const timeout = delayMSec <= 0 ? (0, queue_microtask_1.default)(runner) : setTimeout(runner, delayMSec); | ||
const entry = { | ||
@@ -164,3 +171,5 @@ cancel: () => { | ||
wasCanceled = true; | ||
clearTimeout(timeout); | ||
if (timeout !== undefined) { | ||
clearTimeout(timeout); | ||
} | ||
runQueueEntry === null || runQueueEntry === void 0 ? void 0 : runQueueEntry.cancel(); | ||
@@ -167,0 +176,0 @@ runQueueEntry = undefined; |
{ | ||
"name": "client-run-queue", | ||
"version": "1.1.12", | ||
"version": "2.0.0", | ||
"description": "A client-friendly run queue", | ||
@@ -36,26 +36,27 @@ "keywords": [ | ||
"dependencies": { | ||
"heap": "^0.2.7" | ||
"heap": "^0.2.7", | ||
"queue-microtask": "^1.2.3" | ||
}, | ||
"devDependencies": { | ||
"@types/heap": "^0.2.31", | ||
"@types/jest": "^29.2.5", | ||
"@typescript-eslint/eslint-plugin": "^5.48.1", | ||
"@typescript-eslint/parser": "^5.48.1", | ||
"eslint": "8.31.0", | ||
"@types/jest": "^29.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.50.0", | ||
"@typescript-eslint/parser": "^5.50.0", | ||
"eslint": "8.33.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-import-resolver-typescript": "^3.5.2", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-import-resolver-typescript": "^3.5.3", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-simple-import-sort": "^8.0.0", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-tsdoc": "^0.2.17", | ||
"jest": "29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"madge": "5.0.1", | ||
"prettier": "2.8.2", | ||
"jest": "29.4.1", | ||
"jest-environment-jsdom": "^29.4.1", | ||
"madge": "6.0.0", | ||
"prettier": "2.8.3", | ||
"trash-cli": "5.0.0", | ||
"ts-jest": "^29.0.3", | ||
"ts-jest": "^29.0.5", | ||
"typedoc": "^0.23.24", | ||
"typescript": "4.9.4" | ||
"typescript": "4.9.5" | ||
} | ||
} |
/* istanbul ignore file */ | ||
import queueMicrotask from 'queue-microtask'; | ||
/** | ||
@@ -11,6 +13,13 @@ * A function used to run another function "after interactions". | ||
const defaultRunAfterInteractions: RunAfterInteractionsFunc = (_id, func) => { | ||
const timeout = setTimeout(func, 0); | ||
let wasCanceled = false; | ||
queueMicrotask(() => { | ||
if (wasCanceled) { | ||
return; | ||
} | ||
func(); | ||
}); | ||
return () => { | ||
clearTimeout(timeout); | ||
wasCanceled = true; | ||
}; | ||
@@ -17,0 +26,0 @@ }; |
@@ -67,8 +67,13 @@ import { sleep } from '../../__test_dependency__'; | ||
it('cancelAll should cancel remaining entries on non-empty queue after some entries have run', async () => { | ||
const entries = [1, 2, 3].map((value) => | ||
q.schedule(DEFAULT_PRIORITY, `test${value}`, async () => { | ||
// + 1 to make sure it exceeds DEFAULT_CONTINUOUS_WORK_TIME_LIMIT_MSEC | ||
await sleep(DEFAULT_CONTINUOUS_WORK_TIME_LIMIT_MSEC + 1); | ||
return value; | ||
}) | ||
const entries = [1, 2, 3].map((value, index) => | ||
q.schedule( | ||
DEFAULT_PRIORITY, | ||
`test${value}`, | ||
async () => { | ||
// + 1 to make sure it exceeds DEFAULT_CONTINUOUS_WORK_TIME_LIMIT_MSEC | ||
await sleep(DEFAULT_CONTINUOUS_WORK_TIME_LIMIT_MSEC + 1); | ||
return value; | ||
}, | ||
{ delayMSec: 50 * index } | ||
) | ||
); | ||
@@ -75,0 +80,0 @@ const [firstEntry, ...restEntries] = entries; |
import Heap from 'heap'; | ||
import queueMicrotask from 'queue-microtask'; | ||
@@ -186,3 +187,7 @@ import { runAfterInteractions } from '../config/run-after-interactions'; | ||
const timeout = setTimeout(async () => { | ||
const runner = async () => { | ||
if (wasCanceled) { | ||
return; | ||
} | ||
if (delayedEntryNode !== undefined) { | ||
@@ -215,3 +220,5 @@ this.delayedEntries.remove(delayedEntryNode); | ||
} | ||
}, options.delayMSec); | ||
}; | ||
const delayMSec = options.delayMSec ?? 0; | ||
const timeout = delayMSec <= 0 ? queueMicrotask(runner) : setTimeout(runner, delayMSec); | ||
@@ -227,3 +234,5 @@ const entry: RunQueueEntry<T> = { | ||
wasCanceled = true; | ||
clearTimeout(timeout); | ||
if (timeout !== undefined) { | ||
clearTimeout(timeout); | ||
} | ||
@@ -230,0 +239,0 @@ runQueueEntry?.cancel(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102625
1889
2
+ Addedqueue-microtask@^1.2.3
+ Addedqueue-microtask@1.2.3(transitive)