
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@shutterstock/p-map-iterable
Advanced tools
Async iterable that maps an async iterable input with backpressure.
@shutterstock/p-map-iterable provides several classes that allow processing results of p-map-style mapper functions by iterating the results as they are completed, with back pressure to limit the number of items that are processed ahead of the consumer.
A common use case for @shutterstock/p-map-iterable is as a "prefetcher" that will fetch, for example, AWS S3 files in an AWS Lambda function. By prefetching large files the consumer is able to use 100% of the paid-for Lambda CPU time for the JS thread, rather than waiting idle while the next file is fetched. The backpressure (set by maxUnread) prevents the prefetcher from consuming unlimited memory or disk space by racing ahead of the consumer.
These classes will typically be helpful in batch or queue consumers, not as much in request/response services.
IterableMapper to fetch up to 5 of the next files while the current file is being processed, then pause until the current file is processed and the next file is consumedIterableQueueMapper.enqueue() to write the files back to S3 without waiting for them to finish, unless we get more than, say, 3-4 files being uploaded at once, at which point we can pause until the current file is uploaded before we allow queuing another file for upload.enqueue() and not consume much CPU while waiting for at least 1 upload to finishThe package is available on npm as @shutterstock/p-map-iterable
npm i @shutterstock/p-map-iterable
import { IterableMapper, IterableQueueMapper, IterableQueueMapperSimple } from '@shutterstock/p-map-iterable';
After installing the package, you might want to look at our API Documentation to learn about all the features available.
p-map-iterable vs p-map vs p-queueThese diagrams illustrate the differences in operation betweeen p-map, p-queue, and p-map-iterable.
p-map-iterablep-mapp-queueIterableMapperenqueue methodIterableQueueMappererrors property instead of throwing an AggregateErrorIterable - May rename this before 1.0.0BlockingQueuedequeue blocks until an item is available or until all items have been removed, then returns undefinedenqueue blocks if the queue is fulldone signals that no more items will be added to the queueIterableMapperSee p-map docs for a good start in understanding what this does.
The key difference between IterableMapper and pMap are that IterableMapper does not return when the entire mapping is done, rather it exposes an iterable that the caller loops through. This enables results to be processed while the mapping is still happening, while optionally allowing for back pressure to slow or stop the mapping if the caller is not consuming items fast enough. Common use cases include prefetching items from a remote service - the next set of requests are dispatched asyncronously while the current responses are processed and the prefetch requests will pause when the unread queue fills up.
See examples/iterable-mapper.ts for an example.
Run the example with npm run example:iterable-mapper
IterableQueueMapperIterableQueueMapper is similar to IterableMapper but instead of taking an iterable input it instead adds data via the enqueue method which will block if maxUnread will be reached by the current number of mapper's running in parallel.
See examples/iterable-queue-mapper.ts for an example.
Run the example with npm run example:iterable-queue-mapper
IterableQueueMapperSimpleIterableQueueMapperSimple is similar to IterableQueueMapper but instead exposing the results as an iterable it discards the results as soon as they are ready and exposes any errors through the errors property.
See examples/iterable-queue-mapper-simple.ts for an example.
Run the example with npm run example:iterable-queue-mapper-simple
nvm usenpm inpm run buildnpm run lintnpm run testFAQs
Set of classes used for async prefetching with backpressure (IterableMapper) and async flushing with backpressure (IterableQueueMapper, IterableQueueMapperSimple)
We found that @shutterstock/p-map-iterable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.