blob: 9e29e476c3c5db40eac1d1c2004a6ee4c1e3bb6a [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001import * as fastq from '../'
2
3// Basic example
4
5const queue = fastq(worker, 1)
6
7queue.push('world', (err, result) => {
8 if (err) throw err
9 console.log('the result is', result)
10})
11
12queue.concurrency
13
14queue.drain()
15
16queue.empty = () => undefined
17
18console.log('the queue tasks are', queue.getQueue())
19
20queue.idle()
21
22queue.kill()
23
24queue.killAndDrain()
25
26queue.length
27
28queue.pause()
29
30queue.resume()
31
32queue.saturated = () => undefined
33
34queue.unshift('world', (err, result) => {
35 if (err) throw err
36 console.log('the result is', result)
37})
38
39function worker(task: any, cb: fastq.done) {
40 cb(null, 'hello ' + task)
41}
42
43// Generics example
44
45interface GenericsContext {
46 base: number;
47}
48
49const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1)
50
51genericsQueue.push(7, (err, done) => {
52 if (err) throw err
53 console.log('the result is', done)
54})
55
56genericsQueue.unshift(7, (err, done) => {
57 if (err) throw err
58 console.log('the result is', done)
59})
60
61function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) {
62 cb(null, 'the meaning of life is ' + (this.base * task))
63}