All Projects → fent → Timequeue.js

fent / Timequeue.js

Licence: mit
A queue with custom concurrency and time limit.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Labels

Projects that are alternatives of or similar to Timequeue.js

Onering
A collection of concurrent ring buffers
Stars: ✭ 114 (-15.56%)
Mutual labels:  queue
Cs2223
This a repository for WPI CS2223 Algorithms D Term 2018
Stars: ✭ 121 (-10.37%)
Mutual labels:  queue
Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
Stars: ✭ 125 (-7.41%)
Mutual labels:  queue
Collections.pooled
Fast, low-allocation ports of List, Dictionary, HashSet, Stack, and Queue using ArrayPool and Span.
Stars: ✭ 115 (-14.81%)
Mutual labels:  queue
Ytask
YTask is an asynchronous task queue for handling distributed jobs in golang(go异步任务框架)
Stars: ✭ 121 (-10.37%)
Mutual labels:  queue
Group
轻量级框架 。实现了定时任务功能,分布式任务队列,命令行控制台,数据库脚本自动化,单元测试, rpc服务,多进程服务(模拟map-reduce)等等实用的功能!! 文档 https://fucongcong.gitbooks.io/group-doc/content/.
Stars: ✭ 122 (-9.63%)
Mutual labels:  queue
Promise Queue Plus
Promise-based queue. Support timeout, retry and so on.
Stars: ✭ 113 (-16.3%)
Mutual labels:  queue
Queue
A simple PHP task queue.
Stars: ✭ 125 (-7.41%)
Mutual labels:  queue
Bull Repl
Bull / BullMQ queue command line REPL
Stars: ✭ 121 (-10.37%)
Mutual labels:  queue
Simpleue
PHP queue worker and consumer - Ready for AWS SQS, Redis, Beanstalkd and others.
Stars: ✭ 124 (-8.15%)
Mutual labels:  queue
Unagi Chan
A haskell library implementing fast and scalable concurrent queues for x86, with a Chan-like API
Stars: ✭ 115 (-14.81%)
Mutual labels:  queue
Workq
Job server in Go
Stars: ✭ 1,546 (+1045.19%)
Mutual labels:  queue
Node Rate Limiter Flexible
Node.js rate limit requests by key with atomic increments in single process or distributed environment.
Stars: ✭ 1,950 (+1344.44%)
Mutual labels:  queue
Bilibili member crawler
B站用户爬虫 好耶~是爬虫
Stars: ✭ 115 (-14.81%)
Mutual labels:  queue
Amqp Tools
The amqp tools such as delay strategies and so on.
Stars: ✭ 125 (-7.41%)
Mutual labels:  queue
Rsmq
Redis Simple Message Queue
Stars: ✭ 1,556 (+1052.59%)
Mutual labels:  queue
Data Structures With Go
Data Structures with Go Language
Stars: ✭ 121 (-10.37%)
Mutual labels:  queue
Goconcurrentqueue
Go concurrent-safe, goroutine-safe, thread-safe queue
Stars: ✭ 127 (-5.93%)
Mutual labels:  queue
Bull
Premium Queue package for handling distributed jobs and messages in NodeJS.
Stars: ✭ 11,748 (+8602.22%)
Mutual labels:  queue
Amqp Interop
PHP 7.1+. Promoting the interoperability of AMQPs. It is based on queue-interop
Stars: ✭ 124 (-8.15%)
Mutual labels:  queue

timequeue.js

A queue with custom concurrency and time limits. Inspired by async/queue, but also with variable number of arguments in the worker, events, and with optional time limits.

Dependency Status codecov

Usage

const TimeQueue = require('timequeue');

const worker = (arg1, arg2, callback) => {
  someAsyncFunction(calculation(arg1, arg2), callback);
};

// Worker can be an async function.
const worker = async (arg1) => {
  await anotherSyncFunction(arg1);
  return await andAnotherOne();
};

// create a queue with max 5 concurrency every second
let q = new TimeQueue(worker, { concurrency: 5, every: 1000 });

// Push tasks onto the queue.
q.push(42, 24);
q.push(2, 74);

// Optional callback when pushing tasks.
q.push(2, 2, (err, result) => {
  // task finished
});

// Can use promise/await syntax instead.
let result = await q.push(3, 5);

API

new TimeQueue(worker, [options])

Creates a new instance of a queue. Worker must be a function with a callback for its last argument. The callback must be called in order for the queue to know when the worker has finished a task. options defaults to the following

{
  // Maximum tasks to execute concurrently.
  concurrency: 1

  // How much time in milliseconds to allow no more than
  // the max number of concurrent tasks to run.
  // If the max amount of concurrent tasks finish faster than this time limit,
  // additional tasks will wait until enough time has passed before starting.
, every: 0

  // Maximum number of tasks to keep in the queue.
  // While full, pushed tasks will be ignored.
, maxQueued: Infinity

  // If set, tasks will error if they take too much time.
  // if callback was given to that task, it will be called with the error,
  // otherwise, the returned promise should be `caught`.
, timeout: 0
}

All of these options can later be edited on the queue instance.

TimeQueue#active

How many tasks are currently active.

TimeQueue#intransit

If you use the every option to queue up tasks, this property will be delayed from being updated until there are free spots open for new tasks to begin. active will be updated as soon as a task finishes, even if the next one is just a timeout around the corner.

TimeQueue#queued

How many tasks are currently in the queue.

TimeQueue#finished

How many tasks have finished in total.

TimeQueue#push(data..., [callback])

Pushes a new task to the queue. Any number of arguments can be given. An optional callback can also be given as the last parameter. The callback will be called when the task is finished or if there was any error running the worker.

If the queue is full, pushed tasks will be ignored.

TimeQueue#isFull()

Returns true if queue is full.

TimeQueue#die()

Empties queue and clears the timeouts TimeQueue sets to keep track of running tasks. Currently running tasks will still complete.

Events

Event: 'full'

Queue is full.

Event: 'empty'

Queue is empty, with tasks still running.

Event: 'drain'

Queue is empty and last task has finished.

Install

npm install timequeue

Tests

Tests are written with mocha

npm test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].