Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

client-run-queue

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-run-queue - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0-alpha.0

lib/cjs/run-queue/internal/InternalRunQueueEntryImpl.js

54

lib/cjs/run-queue/queue.js

@@ -23,2 +23,3 @@ "use strict";

const DoubleLinkedList_1 = require("./internal/DoubleLinkedList");
const InternalRunQueueEntryImpl_1 = require("./internal/InternalRunQueueEntryImpl");
class RunQueue {

@@ -81,3 +82,3 @@ // Constructor

let cursor = this.heap.pop();
while (cursor !== undefined && cursor.wasCanceled) {
while (cursor !== undefined && cursor.wasCanceled()) {
cursor = this.heap.pop();

@@ -100,3 +101,2 @@ }

this.processingCount += 1;
next.wasStarted = true;
next.resolve(yield next.run());

@@ -194,40 +194,4 @@ success = true;

var _a, _b, _c;
let resolver;
const entry = {
id,
priority,
wasCanceled: false,
wasCompleted: false,
wasStarted: false,
neverCancel: (_a = options.neverCancel) !== null && _a !== void 0 ? _a : false,
run,
cancel: () => {
var _a, _b;
if (entry.wasCanceled || entry.wasCompleted || entry.neverCancel) {
return false;
}
entry.wasCanceled = true;
resolver({ ok: false, details: consts_1.CANCELED });
(_b = (_a = (0, stats_handler_1.getStatsHandler)()).trackRunQueueDidCancelEntry) === null || _b === void 0 ? void 0 : _b.call(_a, { runQueue: this, entryId: id });
return true;
},
resolve: (value) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
resolver({ ok: true, details: value });
},
reject: (e) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
resolver({ ok: false, details: e });
}
};
const promise = new Promise((resolve) => {
resolver = resolve;
});
// let resolver: (value: RunQueueEntryResult<T> | PromiseLike<RunQueueEntryResult<T>>) => void;
const entry = new InternalRunQueueEntryImpl_1.InternalRunQueueEntryImpl(this, id, priority, (_a = options.neverCancel) !== null && _a !== void 0 ? _a : false, run);
this.heap.push(entry);

@@ -238,11 +202,3 @@ if (this.processingCount < this.maxParallel) {

(_c = (_b = (0, stats_handler_1.getStatsHandler)()).trackRunQueueDidSchedule) === null || _c === void 0 ? void 0 : _c.call(_b, { runQueue: this, entryId: id });
return {
promise,
cancel: () => {
entry.cancel();
},
wasCanceled: () => entry.wasCanceled,
wasCompleted: () => entry.wasCompleted,
wasStarted: () => entry.wasStarted
};
return entry;
};

@@ -249,0 +205,0 @@ this.continuousWorkMaxEntries = (_a = options.continuousWorkMaxEntries) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;

@@ -17,2 +17,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { DoubleLinkedList } from './internal/DoubleLinkedList';
import { InternalRunQueueEntryImpl } from './internal/InternalRunQueueEntryImpl';
export class RunQueue {

@@ -75,3 +76,3 @@ // Constructor

let cursor = this.heap.pop();
while (cursor !== undefined && cursor.wasCanceled) {
while (cursor !== undefined && cursor.wasCanceled()) {
cursor = this.heap.pop();

@@ -94,3 +95,2 @@ }

this.processingCount += 1;
next.wasStarted = true;
next.resolve(yield next.run());

@@ -188,40 +188,4 @@ success = true;

var _a, _b, _c;
let resolver;
const entry = {
id,
priority,
wasCanceled: false,
wasCompleted: false,
wasStarted: false,
neverCancel: (_a = options.neverCancel) !== null && _a !== void 0 ? _a : false,
run,
cancel: () => {
var _a, _b;
if (entry.wasCanceled || entry.wasCompleted || entry.neverCancel) {
return false;
}
entry.wasCanceled = true;
resolver({ ok: false, details: CANCELED });
(_b = (_a = getStatsHandler()).trackRunQueueDidCancelEntry) === null || _b === void 0 ? void 0 : _b.call(_a, { runQueue: this, entryId: id });
return true;
},
resolve: (value) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
resolver({ ok: true, details: value });
},
reject: (e) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
resolver({ ok: false, details: e });
}
};
const promise = new Promise((resolve) => {
resolver = resolve;
});
// let resolver: (value: RunQueueEntryResult<T> | PromiseLike<RunQueueEntryResult<T>>) => void;
const entry = new InternalRunQueueEntryImpl(this, id, priority, (_a = options.neverCancel) !== null && _a !== void 0 ? _a : false, run);
this.heap.push(entry);

@@ -232,11 +196,3 @@ if (this.processingCount < this.maxParallel) {

(_c = (_b = getStatsHandler()).trackRunQueueDidSchedule) === null || _c === void 0 ? void 0 : _c.call(_b, { runQueue: this, entryId: id });
return {
promise,
cancel: () => {
entry.cancel();
},
wasCanceled: () => entry.wasCanceled,
wasCompleted: () => entry.wasCompleted,
wasStarted: () => entry.wasStarted
};
return entry;
};

@@ -243,0 +199,0 @@ this.continuousWorkMaxEntries = (_a = options.continuousWorkMaxEntries) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;

{
"name": "client-run-queue",
"version": "2.1.1",
"version": "2.2.0-alpha.0",
"description": "A client-friendly run queue",

@@ -43,5 +43,5 @@ "keywords": [

"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"eslint": "8.42.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"eslint": "8.44.0",
"eslint-config-prettier": "^8.8.0",

@@ -54,11 +54,17 @@ "eslint-import-resolver-typescript": "^3.5.5",

"eslint-plugin-tsdoc": "^0.2.17",
"jest": "29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest": "29.6.0",
"jest-environment-jsdom": "^29.6.0",
"madge": "6.1.0",
"prettier": "2.8.8",
"trash-cli": "5.0.0",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.1",
"typedoc": "^0.24.8",
"typescript": "5.1.3"
"typescript": "5.1.6"
},
"//resolutions": {
"semver": "7.5.3 due to https://www.npmjs.com/advisories/1092310 affecting dev dependencies (jest, @typescript-eslint/parser, @typescript-eslint/plugin, madge)"
},
"resolutions": {
"semver": "7.5.3"
}
}

@@ -10,2 +10,4 @@ import Heap from 'heap';

import { DoubleLinkedList } from './internal/DoubleLinkedList';
import { InternalRunQueueEntryImpl } from './internal/InternalRunQueueEntryImpl';
import type { InternalRunQueueEntry } from './internal/types/InternalRunQueueEntry';
import type { RunQueueEntry, RunQueueEntryResult } from './types/entry';

@@ -15,27 +17,2 @@ import type { RunQueueOptions } from './types/options';

interface InternalRunQueueEntry<T = any> {
/** A technical but human-readable ID of the entry */
id: string;
/** Lower number is higher priority */
priority: number;
/** If `true`, this entry can't be canceled */
neverCancel: boolean;
/** If `true`, this entry was canceled */
wasCanceled: boolean;
/** If `true`, this entry was completed */
wasCompleted: boolean;
/** If `true`, this entry was started */
wasStarted: boolean;
/** Tries to cancel this entry */
cancel: () => boolean;
/** Called if an error occurred while running this entry */
reject: (e: any) => void;
/** Called when this entry is completed */
resolve: (value: T) => void;
/** Runs this entry */
run: () => Promise<T> | T;
}
export class RunQueue {

@@ -129,3 +106,3 @@ // Public Readonly Fields

let cursor = this.heap.pop();
while (cursor !== undefined && cursor.wasCanceled) {
while (cursor !== undefined && cursor.wasCanceled()) {
cursor = this.heap.pop();

@@ -150,3 +127,2 @@ }

next.wasStarted = true;
next.resolve(await next.run());

@@ -271,45 +247,5 @@ success = true;

): RunQueueEntry<T> => {
let resolver: (value: RunQueueEntryResult<T> | PromiseLike<RunQueueEntryResult<T>>) => void;
const entry: InternalRunQueueEntry<T> = {
id,
priority,
wasCanceled: false,
wasCompleted: false,
wasStarted: false,
neverCancel: options.neverCancel ?? false,
run,
cancel: () => {
if (entry.wasCanceled || entry.wasCompleted || entry.neverCancel) {
return false;
}
// let resolver: (value: RunQueueEntryResult<T> | PromiseLike<RunQueueEntryResult<T>>) => void;
const entry = new InternalRunQueueEntryImpl<T>(this, id, priority, options.neverCancel ?? false, run);
entry.wasCanceled = true;
resolver({ ok: false, details: CANCELED });
getStatsHandler().trackRunQueueDidCancelEntry?.({ runQueue: this, entryId: id });
return true;
},
resolve: (value) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
resolver({ ok: true, details: value });
},
reject: (e) => {
if (entry.wasCompleted || entry.wasCanceled) {
return;
}
entry.wasCompleted = true;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
resolver({ ok: false, details: e });
}
};
const promise = new Promise<RunQueueEntryResult<T>>((resolve) => {
resolver = resolve;
});
this.heap.push(entry);

@@ -323,12 +259,4 @@

return {
promise,
cancel: () => {
entry.cancel();
},
wasCanceled: () => entry.wasCanceled,
wasCompleted: () => entry.wasCompleted,
wasStarted: () => entry.wasStarted
};
return entry;
};
}

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc