@divlook/queue
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

README

CI CD

Install

npm

https://www.npmjs.com/package/@divlook/queue

npm install @divlook/queue

gpr

npm install @divlook/queue --registry=https://npm.pkg.github.com

Usage

Example

const delay = (ms) => new Promise((r) => setTimeout(() => r(), ms))
const que = new Queue()

que.next(() => {
    console.log(1)
    return delay(300)
})
que.next(() => {
    console.log(2)
    return delay(300)
})
que.next(() => {
    console.log(3)
    return delay(300)
})

Import

Module

import { Queue } from '@divlook/queue'

CommonJs

const { Queue } = require('@divlook/queue')

Browser

<script src="https://unpkg.com/@divlook/queue/dist/queue.js"></script>
<script>
    var que = new Queue()
</script>

Error handling

const que = new Queue()

que.addListener('error', (response) => {
    if (response.error) {
        if (Queue.isDefinedError(response.error)) {
            /*
            {
                name: 'QueueError',
                message:
                    | 'Required parameter is missing `typeOrKey`'
                    | 'Listener limit is 1000'
            }
            */
        }

        console.error(response.error)
    }

    // If you want to continue
    que.next()

    // If you want to cancel the remaining tasks
    que.clearQueue()
})

API DOC

Exports

Properties

Methods

Package Sidebar

Install

npm i @divlook/queue

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

8.38 kB

Total Files

6

Last publish

Collaborators

  • uihyeon.cha