# queue-function-api

> Queue function - Nodejs

Latest version **1.0.5** (published 2022-11-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install queue-function-api
pnpm add queue-function-api
yarn add queue-function-api
bun add queue-function-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2022-11-17 |
| First published | 2022-08-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | PhucVo |
| Maintainers | congphuc |
| Keywords | queue, express, express-queue, queue-api, async, concurrency, asynchronous, task, concurrent |

## Links

- npm: https://www.npmjs.com/package/queue-function-api
- Repository: https://github.com/Phuc99bd/queue-function-api
- Homepage: https://github.com/Phuc99bd/queue-function-api#readme
- Issues: https://github.com/Phuc99bd/queue-function-api/issues
- npm.io page: https://npm.io/package/queue-function-api

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2022-11-17
- 1.0.4 — 2022-10-18
- 1.0.3 — 2022-09-05
- 1.0.2 — 2022-08-31
- 1.0.1 — 2022-08-31

## README

# Queue function , Queue function in api

#### Node API adapter in ECMAScript 2015 (ES6)

[![npm](https://img.shields.io/npm/v/npm.svg)](https://www.npmjs.com/package/queue-function-api) [![npm](https://cafedev.vn/wp-content/uploads/2020/07/cafedev_queue_c.png)](https://www.npmjs.com/package/queue-function-api)

## Table of Contents

- [Installation](#installation)
- [How to start](#how-to-start)
- [How to using in api](#how-to-using-in-api)
    
## Installation

Install the `queue-function-api` package in your node server app's local `node_modules` folder.

```bash
npm i queue-function-api
```

### How to start

```bash
const QueueFunction = require('queue-function-api');

/**
 *
 * @param {number} _maxConcurrency
 * @param {array - function} results
 */
const queue = new QueueFunction(1, []);
queue.on('running', function (fn, results = []) {
    console.log(fn)
    console.log("results", results)
});
queue.on('exist', function (fn , results = []) {
     console.log(fn)
     console.log("results", results)

},);
queue.on('error', function (error, results = []) {
     console.log(error)
     console.log("results", results)
});

const delay = (ms) => new Promise((res) => setTimeout(res, ms));

queue.push(async function one() {
  await delay(2000);
  console.log(1);
});

queue.push(async function two() {
  await delay(2000);
  console.log(2);
});

queue.push(async function three() {
  await delay(2500);
  console.log(3);
});

queue.push(async function four() {
  await delay(2000);
  console.log(5);
});

queue.push(async function one() {
  await delay(2000);
  console.log(1);
});

queue.push(async function two() {
  await delay(2000);
  console.log(2);
});

queue.push(async function three() {
  await delay(2500);
  console.log(3);
});

queue.push(async function four() {
  await delay(2000);
  console.log(5);
});
```

```bash
const QueueFunction = require('queue-function-api');
/**
*
* @param {number} _maxConcurrency
* @param {array - function} results
*/
function one(){
    console.log('1');
}
function two(){
    console.log('2');
}
const queue = new QueueFunction(1, [two, one]);
// queue will automatic execute when length results > 0
```
### How to using in api
```bash
const QueueFunction = require('queue-function-api');
/**
*
* @param {number} _maxConcurrency
* @param {array - function} results
*/
const app = express();
app.request.q = new QueueFunction(1);

// function in controller
function getUser(req, res) => {
    const functionQueue = async () => {
        // handle something
        // can be using return response at here
        const data =  await userService.get(req.params.id);
        return await res.send(data)
    }
    req.q.push(functionQueue)
}
```

```bash
const QueueFunction = require('queue-function-api');
/**
*
* @param {number} _maxConcurrency
* @param {array - function} results
*/
const app = express();
global.queue = new Queue(1);

// function in controller
function getUser(req, res) => {
    const functionQueue = async () => {
        // handle something
        // can be using return response at here
        const data =  await userService.get(req.params.id);
        return await res.send(data)
    }
    global.queue.push(functionQueue)
}
```

---
_Source: https://npm.io/package/queue-function-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
