Skip to main content

Queue for your project.

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
64%
Published
3 months ago (0.3.2)

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()

Add Package

deno add @onset/enqueue-task

Import symbol

import * as mod from "@onset/enqueue-task";

Add Package

npx jsr add @onset/enqueue-task

Import symbol

import * as mod from "@onset/enqueue-task";

Add Package

yarn dlx jsr add @onset/enqueue-task

Import symbol

import * as mod from "@onset/enqueue-task";

Add Package

pnpm dlx jsr add @onset/enqueue-task

Import symbol

import * as mod from "@onset/enqueue-task";

Add Package

bunx jsr add @onset/enqueue-task

Import symbol

import * as mod from "@onset/enqueue-task";