Skip to content

Commit

Permalink
updated usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vigan-abd committed Jul 31, 2023
1 parent 01de7c5 commit c72d3d1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ npm test

## Usage
```javascript
const { TaskQueue } = require('@vigan-abd/task-queue-js')
const { TaskQueue, TaskPriorityQueue } = require('@vigan-abd/task-queue-js')

const main = async () => {
const tq = new TaskQueue()
Expand All @@ -35,6 +35,18 @@ const main = async () => {

const batchRes = await Promise.all(promises)
console.log('batch results', batchRes, calcs)

const pq = new TaskPriorityQueue()
pq.initQueue('bar')

const prioriyPromises = []
prioriyPromises.push(pq.pushTask('bar', () => someTask(3000, 1), 2)) // number of priority 2
prioriyPromises.push(pq.pushTask('bar', () => someTask(4000, 2), 1)) // number of priority 1 - higher priority
prioriyPromises.push(pq.pushTask('bar', () => someTask(2000, 3), 5)) // number of priority 5 - low priority
prioriyPromises.push(pq.pushTask('bar', () => someTask(1000, 4), 1))

const priorityBatchRes = await Promise.all(promises)
console.log('priority batch results', priorityBatchRes, calcs.slice(4))
}

main().catch(console.error)
Expand Down

0 comments on commit c72d3d1

Please sign in to comment.