Skip to content

Commit

Permalink
Merge pull request #23 from mixmaxhq/adborroto/PG-62/typescriptify
Browse files Browse the repository at this point in the history
adborroto/PG 62 convert to typescript
  • Loading branch information
adborroto authored Oct 7, 2024
2 parents 523d726 + eddde60 commit d167b56
Show file tree
Hide file tree
Showing 17 changed files with 15,117 additions and 14,463 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

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.
33 changes: 15 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,19 @@ or
$ npm i @mixmaxhq/promise-pool
```

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

* 2.0.0 Add `maxPending` option to avoid problematic usage (see new [Troubleshooting](#troubleshooting) section)
- 3.0.0 Migrate codebase to TypeScript for improved type safety and developer experience.

* 1.1.1 Move `ava` and `ava-spec` to `devDependencies`.
- 2.0.0 Add `maxPending` option to avoid problematic usage (see new [Troubleshooting](#troubleshooting) section)

* 1.1.0 Adds transpilation so it can be used in Node 6 (and prior) environments.
- 1.1.1 Move `ava` and `ava-spec` to `devDependencies`.

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

Troubleshooting
---------------
- 1.0.0 Initial release.

## Troubleshooting

### `cannot queue function in pool`

Expand Down Expand Up @@ -117,7 +115,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 +138,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 +200,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

0 comments on commit d167b56

Please sign in to comment.