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 dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module "queue-promise" {
start(): void;
stop(): void;
dequeue(): any;
enqueue(tasks: TaskFactory | ReadonlyArray<TaskFactory>): void;
enqueue(tasks: TaskFactory | ReadonlyArray<TaskFactory>): number[];
add(tasks: TaskFactory | ReadonlyArray<TaskFactory>): void;
clear(): void;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions dist/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class Queue extends EventEmitter {
return error;
})
.finally(() => {
this.emit("dequeue");
this.emit("dequeue", id);
this.finalize();
})
);
Expand Down Expand Up @@ -237,13 +237,16 @@ export default class Queue extends EventEmitter {
*
* @param {Function|Array} tasks Tasks to add to the queue
* @throws {Error} When task is not a function
* @return {void}
* @return {number[]} Array of task ids
* @access public
*/
enqueue(tasks: Function | Array<Function>): void {
enqueue(tasks: Function | Array<Function>): number[] {
if (Array.isArray(tasks)) {
tasks.map((task) => this.enqueue(task));
return;
const emptyNumberArray: number[] = [];
const taskIds = emptyNumberArray.concat(
tasks.map((task) => this.enqueue(task)[0])
);
return taskIds;
}

if (typeof tasks !== "function") {
Expand All @@ -258,6 +261,8 @@ export default class Queue extends EventEmitter {
if (this.options.start && this.state !== State.STOPPED) {
this.start();
}

return [this.uniqueId];
}

/**
Expand Down
12 changes: 2 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class Queue extends EventEmitter {
return error;
})
.finally(() => {
this.emit("dequeue");
this.emit("dequeue", id);
this.finalize();
})
);
Expand Down Expand Up @@ -237,13 +237,16 @@ export default class Queue extends EventEmitter {
*
* @param {Function|Array} tasks Tasks to add to the queue
* @throws {Error} When task is not a function
* @return {void}
* @return {number[]} Array of task ids
* @access public
*/
enqueue(tasks: Function | Array<Function>): void {
enqueue(tasks: Function | Array<Function>): number[] {
if (Array.isArray(tasks)) {
tasks.map((task) => this.enqueue(task));
return;
const emptyNumberArray: number[] = [];
const taskIds = emptyNumberArray.concat(
tasks.map((task) => this.enqueue(task)[0])
);
return taskIds;
}

if (typeof tasks !== "function") {
Expand All @@ -258,6 +261,8 @@ export default class Queue extends EventEmitter {
if (this.options.start && this.state !== State.STOPPED) {
this.start();
}

return [this.uniqueId];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare module "queue-promise" {
start(): void;
stop(): void;
dequeue(): any;
enqueue(tasks: TaskFactory | ReadonlyArray<TaskFactory>): void;
enqueue(tasks: TaskFactory | ReadonlyArray<TaskFactory>): number[];
add(tasks: TaskFactory | ReadonlyArray<TaskFactory>): void;
clear(): void;
}
Expand Down
6 changes: 3 additions & 3 deletions types/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ queue.stop();
const [e, f, g] = await queue.dequeue();
})();

// $ExpectType void
// $ExpectType number[]
queue.enqueue(() => resolve("Success"));
// $ExpectType void
// $ExpectType number[]
queue.enqueue(() => reject("Error"));
// $ExpectType void
// $ExpectType number[]
queue.enqueue([() => reject("Success"), () => reject("Error")]);
// $ExpectError
queue.enqueue("ab");
Expand Down