Skip to content

feat: add option to set asyncmap/asyncfilter concurrency pool limit#58

Merged
eglitise merged 9 commits intoappium:masterfrom
eglitise:concurrencies
Jan 28, 2026
Merged

feat: add option to set asyncmap/asyncfilter concurrency pool limit#58
eglitise merged 9 commits intoappium:masterfrom
eglitise:concurrencies

Conversation

@eglitise
Copy link
Contributor

This should allow us to replace Bluebird's B.map throughout the org.
Worth noting that B.filter does not have a concurrency option at all.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a concurrency pool limit option to the asyncmap and asyncfilter functions, allowing users to control the level of parallelism when processing collections. This feature aims to replace Bluebird's B.map functionality throughout the organization.

Changes:

  • Added MapFilterOptions type that accepts boolean or {concurrency: number} to control execution mode
  • Implemented worker pool pattern for both asyncmap and asyncfilter with configurable concurrency
  • Updated tests to verify concurrent execution behavior and validation of invalid concurrency values
  • Updated documentation with examples of sequential, parallel, and limited concurrency execution

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
lib/types.ts Added MapFilterOptions type definition to support boolean or concurrency object options
lib/asyncbox.ts Refactored asyncmap and asyncfilter to support concurrency pool limits using worker pattern
test/asyncbox-specs.ts Added tests for concurrency mode, adjusted timing expectations, and added validation tests
README.md Updated documentation with concurrency examples and corrected function signatures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

lib/asyncbox.ts Outdated
coll: T[],
mapper: (value: T) => R | Promise<R>,
runInParallel = true,
mapper: (value: T) => PromiseLike<R>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a breaking change? I assume the previous implementation did not force the mapper to be a promise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the signature only because p-limit required a PromiseLike input. Ultimately the function is intended to be used only for promises, but I'll see if I can somehow adjust it to keep the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added async wrappers for both mapper and filter, which allows to keep the previous signature. I've also added new tests to confirm this.

"singleQuote": true
},
"dependencies": {
"p-limit": "^7.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the main reason for the major version bump was to get rid of any third party dependencies, however now we still add one.

Would you mind if I try to actually implement concurrent mapping and filtering as part of this module without using third party modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't consider the removal of dependencies on its own to require a major version bump. I was merely investigating how to achieve that, and decided to modernize the package along the way, which resulted in the major bumps.
Regarding p-limit specifically, while I still maintain my stance that it's preferable to minimize third party dependencies here, there's 3 main reasons why I added it:

  • Replacing it with native functionality requires somewhat non-trivial code (unlike the previous uses of bluebird and lodash). This is also why I have not attempted to remove lodash from teen_process, since it uses _.isBuffer, whose replacement would require more than a one-liner.
  • It is a very small module (12KB unpacked, compared to 632KB for bluebird and 1.41MB for lodash), and is purpose-built for this use case.
  • It comes from a trusted developer, which gives confidence in the module's coverage of any edge cases.

Hand-rolling the concurrency is certainly still possible, but given the above, I'm not sure if it's worth the effort, even with AI assistance.

@eglitise eglitise merged commit b1e6535 into appium:master Jan 28, 2026
6 checks passed
@eglitise eglitise deleted the concurrencies branch January 28, 2026 06:57
github-actions bot pushed a commit that referenced this pull request Jan 28, 2026
## [6.1.0](v6.0.1...v6.1.0) (2026-01-28)

### Features

* add option to set asyncmap/asyncfilter concurrency pool limit ([#58](#58)) ([b1e6535](b1e6535))

### Miscellaneous Chores

* **deps-dev:** bump @appium/eslint-config-appium-ts ([#59](#59)) ([e38530e](e38530e))
@github-actions
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants