From 6c3bc6e5c3864efab386f68e4cb0a1cf48e924b8 Mon Sep 17 00:00:00 2001 From: kol-oss Date: Sun, 7 Jan 2024 18:15:43 +0200 Subject: [PATCH 1/3] Fix options input --- lib/AsyncObject.js | 2 +- lib/Queue.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AsyncObject.js b/lib/AsyncObject.js index f42d2e1..3404aac 100644 --- a/lib/AsyncObject.js +++ b/lib/AsyncObject.js @@ -21,12 +21,12 @@ class AsyncObject { const id = this.fn(...this.args, (err, data) => { if (err) reject(err); - this.controller = new AbortController(); resolve({ data, args: this.args }); }); signal.addEventListener("abort", () => { if (id) clearTimeout(id); + reject(new Error("Operation is aborted...")); }); }); diff --git a/lib/Queue.js b/lib/Queue.js index 9b281e1..118a538 100644 --- a/lib/Queue.js +++ b/lib/Queue.js @@ -6,7 +6,7 @@ const EventEmitter = require("node:events"); const AsyncObject = require("./AsyncObject"); class Queue { - constructor(streams = 4, options) { + constructor(streams = 4, options = {}) { const { paused } = options; diff --git a/package.json b/package.json index 19d429e..e1d1e3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kol-oss/async-queue", - "version": "1.0.1", + "version": "1.0.2", "description": "Async queue abstraction build on NodeJS", "main": "async-queue.js", "directories": { From 1a9afd1e08203fe5f6a81d3cd7f7ca1c125e058f Mon Sep 17 00:00:00 2001 From: kol-oss Date: Sun, 7 Jan 2024 18:17:44 +0200 Subject: [PATCH 2/3] Change example name --- test/{3-promises.js => 3-async.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/{3-promises.js => 3-async.js} (95%) diff --git a/test/3-promises.js b/test/3-async.js similarity index 95% rename from test/3-promises.js rename to test/3-async.js index 248acef..9cebb3c 100644 --- a/test/3-promises.js +++ b/test/3-async.js @@ -11,7 +11,7 @@ const queue = new Queue(2); // Set listeners callbacks queue .onResume(() => log("Execution started", "process")) - .onSuccess((data, args) => { + .onSuccess(async (data, args) => { log(`URL ${args} parsed:`, "success"); log(data); }) From a6d253248d9e895f66514dc7bf775f90f7f68945 Mon Sep 17 00:00:00 2001 From: kol-oss Date: Sun, 7 Jan 2024 18:19:36 +0200 Subject: [PATCH 3/3] Remove finished from Queue --- lib/Queue.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Queue.js b/lib/Queue.js index 118a538..11bc29c 100644 --- a/lib/Queue.js +++ b/lib/Queue.js @@ -16,15 +16,12 @@ class Queue { this.paused = (paused === undefined) ? true : paused; this.time = undefined; - this.finished = false; this.proccessed = new Map(); this.waiting = []; } push(fn, ...args) { - if (this.finished) throw new Error("Queue is finished"); - const task = new AsyncObject(fn, ...args); this.waiting.push(task);