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.
atomic-batcher
Advanced tools
Readme
A simple batching function that allows you to atomically batch a series of operations. If you are looking for the same thing with a stream interface checkout byte-stream.
npm install atomic-batcher
var batcher = require('atomic-batcher')
var db = require('level')('some.db')
var batch = batcher(function work (ops, cb) {
// only one batch will happen at the time
console.log('Batching:', ops, '\n')
db.batch(ops, cb)
})
batch({type: 'put', key: 'hello', value: 'world-1'})
batch({type: 'put', key: 'hello', value: 'world-2'})
batch({type: 'put', key: 'hello', value: 'world-3'})
batch({type: 'put', key: 'hi', value: 'hello'}, function () {
console.log('Printing latest values:\n')
db.get('hello', console.log) // returns world-3
db.get('hi', console.log) // returns hello
})
Running the above example will print
Batching: [ { type: 'put', key: 'hello', value: 'world-1' } ]
Batching: [ { type: 'put', key: 'hello', value: 'world-2' },
{ type: 'put', key: 'hello', value: 'world-3' },
{ type: 'put', key: 'hi', value: 'hello' } ]
Printing latest values:
null 'world-3'
null 'hello'
var batch = batcher(worker)
Create a new batching function. worker
should be a function that accepts a batch and a callback, (batch, cb)
.
Only one batch is guaranteed to be run at the time.
The batch
function accepts a value or an array of values and a callback, batch(value(s), cb)
. The callback is called when the batch containing the values have been run.
MIT
FAQs
A simple batching function that allows you to atomically batch a series of operations.
The npm package atomic-batcher receives a total of 283,007 weekly downloads. As such, atomic-batcher popularity was classified as popular.
We found that atomic-batcher 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.