Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

example.ts 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as fastq from '../'
  2. // Basic example
  3. const queue = fastq(worker, 1)
  4. queue.push('world', (err, result) => {
  5. if (err) throw err
  6. console.log('the result is', result)
  7. })
  8. queue.concurrency
  9. queue.drain()
  10. queue.empty = () => undefined
  11. console.log('the queue tasks are', queue.getQueue())
  12. queue.idle()
  13. queue.kill()
  14. queue.killAndDrain()
  15. queue.length
  16. queue.pause()
  17. queue.resume()
  18. queue.saturated = () => undefined
  19. queue.unshift('world', (err, result) => {
  20. if (err) throw err
  21. console.log('the result is', result)
  22. })
  23. function worker(task: any, cb: fastq.done) {
  24. cb(null, 'hello ' + task)
  25. }
  26. // Generics example
  27. interface GenericsContext {
  28. base: number;
  29. }
  30. const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1)
  31. genericsQueue.push(7, (err, done) => {
  32. if (err) throw err
  33. console.log('the result is', done)
  34. })
  35. genericsQueue.unshift(7, (err, done) => {
  36. if (err) throw err
  37. console.log('the result is', done)
  38. })
  39. function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) {
  40. cb(null, 'the meaning of life is ' + (this.base * task))
  41. }