Skip to content

Repository files navigation

Cute & simple, robust, persistable job & task queue written in typescript. Full type safety included. ✌🏼

importcreateQueuefrom'queue-tea'interfaceTasks{syncDataWithCloud: {username: string;count: number}runInBackground: undefined}constqueue=createQueue<Tasks>({tasks: {syncDataWithCloud: async({ username, count })=>{fetch('http://example.com/api/',{body: JSON.stringify({ username, count }),})},runInBackground: async(_options,{ createdAt, retries })=>{// This is a fun task, that fails 3 times, than succeedsif(retries<2){thrownewError('Not this time')}return},},})queue.queueTask('syncDataWithCloud',{username: 'rainbow cat',count: 69})queue.queueTask('runInBackground')queue.run()

Installation

You know the drill 👏

yarn add queue-tea
### or for the npm fans
npm install --save queue-tea

Introduction

queue-tea is meant to be a local queue for Javascript applications running for React Native, Electron or the browser.

We use it to ensure some tasks that should be performed in the background, can fail and can be retried. It's also persistable by serializing it and providing the state as initialState.

How it works

Options

OptionValueDefault value
initialStateTask[][]
onChangeonChange?: (queue: QueueType<G>) => Promise<void>;undefined
retryDelay(retries: number) => numberdefaultBackOff

Retrying

The queue relies on exceptions. When a tasks fails, it should throw an exception. It then will be retried.

Info: By default, the task will be retried every 1 second * retries + $noise with a maximum of 5 seconds. You can change this by providing your own function to the retryDelay option.

About

Cute job & task queue – type safe

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages