Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AsyncObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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..."));
});
});
Expand Down
5 changes: 1 addition & 4 deletions lib/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion test/3-promises.js → test/3-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down