@efebia/queue 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/queue.d.ts +2 -1
- package/lib/queue.js +5 -3
- package/package.json +1 -1
package/lib/queue.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type QueueOptions = {
|
|
2
2
|
sleepTimeout: number;
|
|
3
3
|
errorCallback: (error: any) => void | Promise<void>;
|
|
4
|
+
doneCallback: () => void | Promise<void>;
|
|
4
5
|
};
|
|
5
6
|
export type QueueCallback<TMessage> = (name: string, params: TMessage, state: {
|
|
6
7
|
del: boolean;
|
|
@@ -25,5 +26,5 @@ export declare abstract class Queue<TReceivedMessage, TMessage extends object =
|
|
|
25
26
|
stop(): void;
|
|
26
27
|
resume(...args: Parameters<typeof this.start>): Promise<void>;
|
|
27
28
|
isRunning(): boolean;
|
|
28
|
-
send(body: Message<TMessage>): void
|
|
29
|
+
send(body: Message<TMessage>): Promise<void>;
|
|
29
30
|
}
|
package/lib/queue.js
CHANGED
|
@@ -7,7 +7,8 @@ class Queue {
|
|
|
7
7
|
this.forever = true;
|
|
8
8
|
this.options = Object.assign({
|
|
9
9
|
sleepTimeout: 5000,
|
|
10
|
-
errorCallback: (e) => console.error(e)
|
|
10
|
+
errorCallback: (e) => console.error(e),
|
|
11
|
+
doneCallback: () => Promise.resolve()
|
|
11
12
|
}, opts);
|
|
12
13
|
}
|
|
13
14
|
async start(callback, canThrow = false) {
|
|
@@ -19,6 +20,7 @@ class Queue {
|
|
|
19
20
|
for (const message of messages) {
|
|
20
21
|
await this.processMessage(message, callback);
|
|
21
22
|
}
|
|
23
|
+
await this.options.doneCallback();
|
|
22
24
|
}
|
|
23
25
|
catch (error) {
|
|
24
26
|
if (canThrow)
|
|
@@ -38,9 +40,9 @@ class Queue {
|
|
|
38
40
|
isRunning() {
|
|
39
41
|
return this.forever;
|
|
40
42
|
}
|
|
41
|
-
send(body) {
|
|
43
|
+
async send(body) {
|
|
42
44
|
const updatedBody = Object.assign(Object.assign({}, body), { params: Object.assign(Object.assign({}, body.params), { createdAt: new Date() }) });
|
|
43
|
-
this.sendMessage(updatedBody);
|
|
45
|
+
await this.sendMessage(updatedBody);
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
exports.Queue = Queue;
|