Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
autobatch-promise
Advanced tools
Automatically split work into batches. A promise-based concurrency primitive.
Readme
Sometimes work can be done quicker in batches (e.g. inserting multiple rows into a database in one transaction, or making a request to a remote server that supports batch requests). This package helps to automatically collect individual calls (items of work) into batches.
While one batch is busy being flushed, another batch is prepared in background to be flushed next. Error handling resizes batches to find and prune any items that cause errors.
Order of items is always preserved.
const Autobatch = require('autobatch');
const batch = new Autobatch(flushCallback, {onError, maxBatchSize, maxQueueSize})
…
batch.add("item1");
batch.add("item2");
batch.add("item3");
new Autobatch(cb, options)
flushCallback(batchArray)
— function receiving an array if items to flush. If it throws an error when the batch contains more than one item, the items will be flushed again in a smaller batch.onError(error, item)
— callback called whenever the flushCallback
failed to flush the item.maxBatchSize
— maximum number of items to flush in one go. 0 (the default) means no limit.maxQueueSize
— maximum number of items stored and waiting to be flushed. When there are more items than this limit, some items will be dropped. 0 (the default) means no limit (other than Node running out of memory).autobatch.add(item, [ item… ])
Queues all arguments as items to be flushed. The items can be any JS value. They will be passed as-is to the flushCallback
.
Returns a Promise
which will resolve when all items are flushed. It never returns errors.
autobatch.flush()
Waits until all items are flushed. It never returns errors. It's not necessary to call this function, since add()
flushes as well.
FAQs
Automatically split work into batches. A promise-based concurrency primitive.
The npm package autobatch-promise receives a total of 3 weekly downloads. As such, autobatch-promise popularity was classified as not popular.
We found that autobatch-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.