
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Batches asynchronous requests.
You might have something like this:
getUser(1, function (error, user) {
displayUser(user);
});
getUser(2, function (error, user) {
displayUser(user);
});
getUser(3, function (error, user) {
displayUser(user);
});
This would ordinarily result in 3 individual calls for users:
http://.../users/1
http://.../users/2
http://.../users/3
But what if you wanted to make just one request, with an API like this:
http://.../users?id=1&id=2&id=3
Use batchy:
var getUser = batchy(function (userIds, callback) {
var ids = userIds.map(function (id) { return 'id=' + id; }).join('&');
$.get('http://.../users?' + ids)
.done(function (data) {
callback(undefined, data);
})
.error(function (error) {
callback(error);
});
});
Batchy will batch requests up into groups of 10, or into time segments of 140ms, which ever comes first.
var mapItem = batchy(map, [options])
where:
map(items, [callback(error, mappedItems)])
- a function accepting items and callback. The function is to process the items and call the callback. The result (second argument to callback) is the list of mapped items. This function can also be synchronous if you omit the callback parameter, in which case just return
the mapped items.options
- can contain:
size
- the maximum size of each batch (default 10)timeout
- the maximum time to wait for items to batch (default 140ms)It returns a new function that looks like this:
mapItem(item, callback)
where:
item
- an item to mapcallback(error, mappedItem)
- a function that will be called when the item is eventually mapped.FAQs
for running asynchronous tasks in batches
The npm package batchy receives a total of 0 weekly downloads. As such, batchy popularity was classified as not popular.
We found that batchy 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.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.