jessetane / queue

Asynchronous function queue with adjustable concurrency
MIT License
762 stars 66 forks source link

Queue of Queues #68

Closed aymengraoui closed 5 years ago

aymengraoui commented 5 years ago

hello, thanks for the module i started using it about 3 days ago and im having so much fun with it, the thing is i wanna make a BIGQueue for multiple MINIQueues and im gonna use the UI to pause and start the MINIQueues inside the BIGQueue but im stuck in a position where i dont know the index of the MINIQueues. thanks

balupton commented 5 years ago

Perhaps https://github.com/bevry/taskgroup would suite your needs

jessetane commented 5 years ago

@aymengraoui can you post some simple example code that demonstrates the issue?

aymengraoui commented 5 years ago

hey guys sorry for taking too long to response i was working on that and i managed to make it work, now i can have control on both MINIQueues !!

let Item1 = {
  Id: 'id',
  linksToDownloads: [
    'link1',
    'link2'
  ]
}

let Item2 = {
  Id: 'id2',
  linksToDownloads: [
    'link1',
    'link2'
  ]
}
let BIGQueue = Queue({
  autostart: true,
  concurrency: 1
})
let MINIQueue = Queue({
  autostart: false,
  concurrency: 1
})
// 
//   create 2 MINIQueues with Item1 and Item2
//
BIGQueue.push(next => {
      updateListOfDownloads(Item.Id, DownloadStatus.DOWNLOADING)
      eventCatcher.on('PauseDownload', (id) => {
        if (item.Id === id) {
          updateListOfDownloads(id, DownloadStatus.PAUSED)
          MINIQueue.stop()
        }
      })
      eventCatcher.on('ResumeDownload', (id) => {
        if (item.Id === id) {
          updateListOfDownloads(id, DownloadStatus.DOWNLOADING)
          MINIQueue.start()
        }
      })
      eventCatcher.on('CancelDownload', (id) => {
        if (course.Id === id) {
          MINIQueue.end()
        }
      })
      MINIQueue.start((err) => {
        if (err) throw err
        updateListOfDownloads(bigItem.Id, DownloadStatus.FINISHED)
        next()
      })
})

thank you