Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adborroto/PG 62 convert to typescript #23

Merged
merged 10 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": ["mixmax/node", "mixmax/prettier"]
"extends": [
"mixmax/node",
"mixmax/prettier"
]
}
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: continuous-integration

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
checks:
uses: mixmaxhq/github-workflows-public/.github/workflows/checks.yml@main
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ node_modules
.node_repl_history
.DS_Store
*.sublime-workspace
/dist
/dist
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.20.0
File renamed without changes.
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
promise-pool
============
# promise-pool

Concurrent control of async function invocation with a pool-like abstraction. Implicitly applies
backpressure to the imperative task producer.
Expand All @@ -11,11 +10,11 @@ import PromisePool from '@mixmaxhq/promise-pool';

async function sample() {
// Cap the concurrent function execution at 10.
const pool = new PromisePool({numConcurrent: 10});
const pool = new PromisePool({ numConcurrent: 10 });

// Call an async function 1000000 times. The pool ensures that no more than
// 10 will be executing at a time.
for (let i = 0; i < 1000000; ++i) {
for (const i = 0; i < 1000000; ++i) {
// The await suspends the for loop until the function has started.
await pool.start(async (i) => {
await sendResult(await getResult(i));
Expand Down Expand Up @@ -46,8 +45,7 @@ has built-in backpressure, to simplify writing concurrent code that avoids loadi
memory. This module is a rewrite of the [synchronize-pool][] module, but instead of using
synchronize, it uses async/await.

Install
-------
## Install

We're hoping to use the `promise-pool` package name, but it's currently occupied.

Expand All @@ -61,19 +59,17 @@ or
$ npm i @mixmaxhq/promise-pool
```

Changelog
---------
## Changelog

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update this? Or remove it altogether, if we'll be maintaining a CHANGELOG file?

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 think we should yes. But I don't know how to publish this package. Should I do it manually ?
@bradvogel do you know?, last release was 5y ago.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, the old school way :-/. This repo doesn't have semantic-release that auto-publishes.

You should be able to run mixmax dev npm publish (instructions here) which runs this script.

* 2.0.0 Add `maxPending` option to avoid problematic usage (see new [Troubleshooting](#troubleshooting) section)
- 2.0.0 Add `maxPending` option to avoid problematic usage (see new [Troubleshooting](#troubleshooting) section)

* 1.1.1 Move `ava` and `ava-spec` to `devDependencies`.
- 1.1.1 Move `ava` and `ava-spec` to `devDependencies`.

* 1.1.0 Adds transpilation so it can be used in Node 6 (and prior) environments.
- 1.1.0 Adds transpilation so it can be used in Node 6 (and prior) environments.

* 1.0.0 Initial release.
- 1.0.0 Initial release.

Troubleshooting
---------------
## Troubleshooting

### `cannot queue function in pool`

Expand Down Expand Up @@ -117,7 +113,7 @@ Instead, you need to use some iteration method that preserves backpressure, like

```js
async function startJobs() {
const pool = new PromisePool({numConcurrent: 4});
const pool = new PromisePool({ numConcurrent: 4 });

// Still severely suboptimal.
const users = await db.users.findAsCursor().toArray();
Expand All @@ -140,7 +136,7 @@ Or even better, couple this with a call to `promise-iterate` to only load users
import promiseIterate from 'promise-iterate';

async function startJobs() {
const pool = new PromisePool({numConcurrent: 4});
const pool = new PromisePool({ numConcurrent: 4 });

const users = await db.users.findAsCursor();

Expand Down Expand Up @@ -202,8 +198,7 @@ async function sendEmails(pool, users) {
}
```

License
-------
## License

> The MIT License (MIT)
>
Expand Down
11 changes: 0 additions & 11 deletions index.js

This file was deleted.

16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
clearMocks: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
testRegex: '/((test|spec)s?|src)/.*([Tt]est|[Ss]pec)\\.(ts|js)$',
testEnvironment: 'node',
moduleNameMapper: {
'^mongodbMapped$': `mongodb${process.env.DRIVER_VERSION || ''}`,
},
testTimeout: 15000,
};
Loading
Loading