strong-tie/inbound-calls
0
1import * as fastq from '../'2import { promise as queueAsPromised } from '../'3 4// Basic example5 6const queue = fastq(worker, 1)7 8queue.push('world', (err, result) => {9 if (err) throw err10 console.log('the result is', result)11})12 13queue.push('push without cb')14 15queue.concurrency16 17queue.drain()18 19queue.empty = () => undefined20 21console.log('the queue tasks are', queue.getQueue())22 23queue.idle()24 25queue.kill()26 27queue.killAndDrain()28 29queue.length30 31queue.pause()32 33queue.resume()34 35queue.running()36 37queue.saturated = () => undefined38 39queue.unshift('world', (err, result) => {40 if (err) throw err41 console.log('the result is', result)42})43 44queue.unshift('unshift without cb')45 46function worker(task: any, cb: fastq.done) {47 cb(null, 'hello ' + task)48}49 50// Generics example51 52interface GenericsContext {53 base: number;54}55 56const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1)57 58genericsQueue.push(7, (err, done) => {59 if (err) throw err60 console.log('the result is', done)61})62 63genericsQueue.unshift(7, (err, done) => {64 if (err) throw err65 console.log('the result is', done)66})67 68function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) {69 cb(null, 'the meaning of life is ' + (this.base * task))70}71 72const queue2 = queueAsPromised(asyncWorker, 1)73 74async function asyncWorker(task: any) {75 return 'hello ' + task76}77 78async function run () {79 await queue.push(42)80 await queue.unshift(42)81}82 83run()84 