UNPKG

748 BPlain TextView Raw
1import * as fs from 'fs';
2import * as core from '@akala/core'
3
4export class Queue<T> extends core.Queue<T>
5{
6 private filePath: string;
7
8 constructor(handler: (message: T, next: (processed: boolean) => void) => void, queue?: T[] | string)
9 {
10 if (typeof (queue) == 'string')
11 {
12 var queueObj = JSON.parse(fs.readFileSync(queue, 'utf8'));
13 super(handler, queueObj);
14 this.filePath = queue;
15 }
16 else
17 super(handler, queue);
18 }
19
20 public save()
21 {
22 if (this.filePath)
23 fs.writeFile(this.filePath, JSON.stringify(this.pending), function (err)
24 {
25 if (err)
26 console.error(err);
27 });
28 }
29}
\No newline at end of file