Socket
Socket
Sign inDemoInstall

@dramaorg/fugit-reprehenderit-dignissimos

Package Overview
Dependencies
41
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dramaorg/fugit-reprehenderit-dignissimos

![ci][ci-url] [![npm version][npm-badge]][npm-url]


Version published
Weekly downloads
187
decreased by-35.52%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@dramaorg/fugit-reprehenderit-dignissimos

ci npm version

Fast, in memory work queue.

Benchmarks (1 million tasks):

  • setImmediate: 812ms
  • @dramaorg/fugit-reprehenderit-dignissimos: 854ms
  • async.queue: 1298ms
  • neoAsync.queue: 1249ms

Obtained on node 12.16.1, on a dedicated server.

If you need zero-overhead series function call, check out fastseries. For zero-overhead parallel function call, check out fastparallel.

js-standard-style

Install

npm i @dramaorg/fugit-reprehenderit-dignissimos --save

Usage (callback API)

'use strict'

const queue = require('@dramaorg/fugit-reprehenderit-dignissimos')(worker, 1)

queue.push(42, function (err, result) {
  if (err) { throw err }
  console.log('the result is', result)
})

function worker (arg, cb) {
  cb(null, arg * 2)
}

Usage (promise API)

const queue = require('@dramaorg/fugit-reprehenderit-dignissimos').promise(worker, 1)

async function worker (arg) {
  return arg * 2
}

async function run () {
  const result = await queue.push(42)
  console.log('the result is', result)
}

run()

Setting "this"

'use strict'

const that = { hello: 'world' }
const queue = require('@dramaorg/fugit-reprehenderit-dignissimos')(that, worker, 1)

queue.push(42, function (err, result) {
  if (err) { throw err }
  console.log(this)
  console.log('the result is', result)
})

function worker (arg, cb) {
  console.log(this)
  cb(null, arg * 2)
}

Using with TypeScript (callback API)

'use strict'

import * as @dramaorg/fugit-reprehenderit-dignissimos from "@dramaorg/fugit-reprehenderit-dignissimos";
import type { queue, done } from "@dramaorg/fugit-reprehenderit-dignissimos";

type Task = {
  id: number
}

const q: queue<Task> = @dramaorg/fugit-reprehenderit-dignissimos(worker, 1)

q.push({ id: 42})

function worker (arg: Task, cb: done) {
  console.log(arg.id)
  cb(null)
}

Using with TypeScript (promise API)

'use strict'

import * as @dramaorg/fugit-reprehenderit-dignissimos from "@dramaorg/fugit-reprehenderit-dignissimos";
import type { queueAsPromised } from "@dramaorg/fugit-reprehenderit-dignissimos";

type Task = {
  id: number
}

const q: queueAsPromised<Task> = @dramaorg/fugit-reprehenderit-dignissimos.promise(asyncWorker, 1)

q.push({ id: 42}).catch((err) => console.error(err))

async function asyncWorker (arg: Task): Promise<void> {
  // No need for a try-catch block, @dramaorg/fugit-reprehenderit-dignissimos handles errors automatically
  console.log(arg.id)
}

API


@dramaorg/fugit-reprehenderit-dignissimosueue([that], worker, concurrency)

Creates a new queue.

Arguments:

  • that, optional context of the worker function.
  • worker, worker function, it would be called with that as this, if that is specified.
  • concurrency, number of concurrent tasks that could be executed in parallel.

queue.push(task, done)

Add a task at the end of the queue. done(err, result) will be called when the task was processed.


queue.unshift(task, done)

Add a task at the beginning of the queue. done(err, result) will be called when the task was processed.


queue.pause()

Pause the processing of tasks. Currently worked tasks are not stopped.


queue.resume()

Resume the processing of tasks.


queue.idle()

Returns false if there are tasks being processed or waiting to be processed. true otherwise.


queue.length()

Returns the number of tasks waiting to be processed (in the queue).


queue.getQueue()

Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks


queue.kill()

Removes all tasks waiting to be processed, and reset drain to an empty function.


queue.killAndDrain()

Same than kill but the drain function will be called before reset to empty.


queue.error(handler)

Set a global error handler. handler(err, task) will be called each time a task is completed, err will be not null if the task has thrown an error.


queue.concurrency

Property that returns the number of concurrent tasks that could be executed in parallel. It can be altered at runtime.


queue.drain

Function that will be called when the last item from the queue has been processed by a worker. It can be altered at runtime.


queue.empty

Function that will be called when the last item from the queue has been assigned to a worker. It can be altered at runtime.


queue.saturated

Function that will be called when the queue hits the concurrency limit. It can be altered at runtime.


@dramaorg/fugit-reprehenderit-dignissimosueue.promise([that], worker(arg), concurrency)

Creates a new queue with Promise apis. It also offers all the methods and properties of the object returned by @dramaorg/fugit-reprehenderit-dignissimosueue with the modified push and unshift methods.

Node v10+ is required to use the promisified version.

Arguments:

  • that, optional context of the worker function.
  • worker, worker function, it would be called with that as this, if that is specified. It MUST return a Promise.
  • concurrency, number of concurrent tasks that could be executed in parallel.

queue.push(task) => Promise

Add a task at the end of the queue. The returned Promise will be fulfilled (rejected) when the task is completed successfully (unsuccessfully).

This promise could be ignored as it will not lead to a 'unhandledRejection'.

queue.unshift(task) => Promise

Add a task at the beginning of the queue. The returned Promise will be fulfilled (rejected) when the task is completed successfully (unsuccessfully).

This promise could be ignored as it will not lead to a 'unhandledRejection'.

queue.drained() => Promise

Wait for the queue to be drained. The returned Promise will be resolved when all tasks in the queue have been processed by a worker.

This promise could be ignored as it will not lead to a 'unhandledRejection'.

License

ISC

Keywords

FAQs

Last updated on 11 Jun 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc