enqueue-task
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

Enqueue task npm npm type definitions jsr

Queue for your project.

Installation

npm install enqueue-task

Usage

Queue

import { queue } from 'enqueue-task'

const delay = (milliseconds: number) =>
	new Promise((resolve) => setTimeout(resolve, milliseconds))

const task1 = async () => {
	await delay(5000)
	console.log('Task 1')
}
const task2 = async () => {
	await delay(3500)
	console.log('Task 2')
}
const task3 = async () => {
	await delay(4000)
	console.log('Task 3')
}

queue.enqueueTask(task1)
queue.enqueueTask(task2)
queue.enqueueTask(task3)

Console output

'Task 1' // After 5 seconds
'Task 2' // After 8.5 seconds
'Task 3' // After 12.5 seconds

Custom queue

import { createQueue } from 'enqueue-task'
const myQueue = createQueue()

Return value

const task4 = async () => {
	await delay(1000)
	return 3.14159265358979
}
const result4 = await queue.enqueueTask(task4)
console.log(result4) // 3.14159265358979

Group helper

import { getQueueGroup } from 'enqueue-task'

getQueueGroup('apples').enqueueTask(task1)
getQueueGroup('apples').enqueueTask(task2)
getQueueGroup('pears').enqueueTask(task3)

Console output

'Task 3' // After 4 seconds
'Task 1' // After 5 seconds
'Task 2' // After 8.5 seconds

Custom get queue group

import { createGetQueueGroup } from 'enqueue-task'
const myGetQueueGroup = createGetQueueGroup()

Package Sidebar

Install

npm i enqueue-task

Weekly Downloads

119

Version

0.3.2

License

ISC

Unpacked Size

10.7 kB

Total Files

17

Last publish

Collaborators

  • onset