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..11bc29c 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; @@ -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); 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": { 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); })