pop-queue-system
v0.1.1
Published
Helps queue tasks in node.js, in a simplistic way.
Downloads
2
Readme
A package that allows you to queue tasks.
Example:
let QueueSystem = require('pop-queue-system')
let Queue1 = new QueueSystem.Queue() //Create new queue thread
Queue1.wait().then(turn => { //Wait for queue to get to task, can also be used with await.
console.log("Waited 1!")
setTimeout(function() {
console.log("Finished.")
Queue1.finishWait(turn) //Mark the task as finished and move onto the next task.
}, 1000)
})
Queue1.wait(10).then(turn => { //Previous task has been marked as finished. 10 is optional and is the interval between each check.
//(checks check if all previous tasks were finished, lower the number the more memory usage)
console.log("Waited 2!")
setTimeout(function() {
Queue1.finishWait(turn) //Mark as finished and move onto next task
}, 1000)
})
First, we require and create a new queue like so:
let QueueSystem = require('pop-queue-system')
let Queue1 = new QueueSystem.Queue() //Create new queue thread
Then, we add a wait that waits for any previous tasks to finish.
let QueueSystem = require('pop-queue-system')
let Queue1 = new QueueSystem.Queue() //Create new queue thread
Queue1.wait().then(turn => { //Wait for queue to get to task, can also be used with await.
})
Inside the task, we can reserve the time to do the task and when done, call the finishWait function on our queue.
let QueueSystem = require('pop-queue-system')
let Queue1 = new QueueSystem.Queue() //Create new queue thread
Queue1.wait().then(turn => { //Wait for queue to get to task, can also be used with await.
console.log("Waited 1!")
setTimeout(function() {
console.log("Finished.")
Queue1.finishWait(turn) //Mark the task as finished and move onto the next task.
}, 1000)
})
Turn represents the task number and is used by finishWait to move on.