Skip to content

Commit feebe8d

Browse files
committed
repo renaming
1 parent 4d2ae93 commit feebe8d

14 files changed

Lines changed: 601 additions & 568 deletions

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

Readme.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Async Queue
1+
# Async Pool
22

33
Process asynchronous tasks with controlled max concurrency and memory efficiency.
44

5-
![NPM Version](https://img.shields.io/npm/v/%40aherve%2Fasync-queue)
6-
![NPM Downloads](https://img.shields.io/npm/dm/%40aherve%2Fasync-queue)
7-
![NPM License](https://img.shields.io/npm/l/%40aherve%2Fasync-queue)
8-
![npm bundle size](https://img.shields.io/bundlephobia/min/%40aherve%2Fasync-queue)
5+
![NPM Version](https://img.shields.io/npm/v/%40aherve%2Fasync-pool)
6+
![NPM Downloads](https://img.shields.io/npm/dm/%40aherve%2Fasync-pool)
7+
![NPM License](https://img.shields.io/npm/l/%40aherve%2Fasync-pool)
8+
![npm bundle size](https://img.shields.io/bundlephobia/min/%40aherve%2Fasync-pool)
99

1010

1111
## Features
@@ -17,36 +17,36 @@ Process asynchronous tasks with controlled max concurrency and memory efficiency
1717
## Installation
1818

1919
```bash
20-
npm install @aherve/async-queue
20+
npm install @aherve/async-pool
2121
```
2222

2323
```typescript
2424
// with TypeScript or ES Modules
25-
import { AsyncQueue } from "@aherve/async-queue";
25+
import { AsyncPool } from "@aherve/async-pool";
2626

2727
// or with CommonJS
28-
const AsyncQueue = require("@aherve/async-queue").AsyncQueue;
28+
const AsyncPool = require("@aherve/async-pool").AsyncPool;
2929
```
3030

3131
## Usage
3232

3333
### Consume results as a stream
3434
```typescript
35-
const queue = new AsyncQueue<number>() // generic can optionally be used
35+
const pool = new AsyncPool<number>() // generic can optionally be used
3636
.withConcurrency(10)
3737
.withRetries(3); // default number of retries for each task unless specified at task level
3838

39-
// enqueue many tasks
39+
// add many tasks
4040
for (let i = 0; i < 100; i++) {
41-
queue.enqueue({
41+
pool.add({
4242
task: async () => 2 * i,
43-
maxRetries: 3, // optional, will override the queue's default when set
43+
maxRetries: 3, // optional, will override the pool's default when set
4444
});
4545
}
4646

4747
// consume results as a stream, without building a large array of results
4848
let sum = 0;
49-
for await (const res of queue.results()) {
49+
for await (const res of pool.results()) {
5050
sum += res;
5151
}
5252

@@ -63,51 +63,51 @@ const task = async () => {
6363
console.log("hello, world");
6464
};
6565

66-
// create queue and add some tasks
67-
const queue = new AsyncQueue()
66+
// create pool and add some tasks
67+
const pool = new AsyncPool()
6868
.withConcurrency(10)
6969
.withRetries(3)
70-
.enqueue({ task })
71-
.enqueue({ task })
72-
.enqueue({ task });
70+
.add({ task })
71+
.add({ task })
72+
.add({ task });
7373

7474
// wait until all tasks are processed
75-
await queue.waitForTermination();
75+
await pool.waitForTermination();
7676
```
7777

7878
### Promise-based consumption
7979

8080
Similar to `Promise.all`, but with controlled concurrency and builtin retries
8181

8282
```typescript
83-
const queue = new AsyncQueue();
83+
const pool = new AsyncPool();
8484

85-
queue.enqueue({ task: async () => 1 });
86-
queue.enqueue({ task: async () => true });
87-
queue.enqueue({ task: async () => "hello" });
85+
pool.add({ task: async () => 1 });
86+
pool.add({ task: async () => true });
87+
pool.add({ task: async () => "hello" });
8888

89-
const results = await queue.all();
89+
const results = await pool.all();
9090
console.log(results); // [1, true, "hello"], order not guaranteed (especially if retries happened)
9191
```
9292

9393
### Using generic typings
9494

95-
You can specify a generic type for the `AsyncQueue` to enforce type safety on the results of the tasks. If you don't specify a type, it will default to `unknown`, allowing any type of result.
95+
You can specify a generic type for the `AsyncPool` to enforce type safety on the results of the tasks. If you don't specify a type, it will default to `unknown`, allowing any type of result.
9696

9797
```typescript
98-
const typedQueue = new AsyncQueue<string>();
98+
const typedPool = new AsyncPool<string>();
9999

100-
typedQueue.enqueue({ task: async () => "hello" }); // OK
101-
typedQueue.enqueue({ task: async () => 1 }); // ❌ Error: Type 'Promise<number>' is not assignable to type 'Promise<string>'.
100+
typedPool.add({ task: async () => "hello" }); // OK
101+
typedPool.add({ task: async () => 1 }); // ❌ Error: Type 'Promise<number>' is not assignable to type 'Promise<string>'.
102102

103-
// typedQueue.all() will return a Promise<string[]>, typedQueue.results() is an AsyncGenerator<string>
103+
// typedPool.all() will return a Promise<string[]>, typedPool.results() is an AsyncGenerator<string>
104104

105-
const relaxedQueue = new AsyncQueue();
105+
const relaxedPool = new AsyncPool();
106106

107-
relaxedQueue.enqueue({ task: async () => "hello" }); // OK
108-
relaxedQueue.enqueue({ task: async () => 1 }); // OK
107+
relaxedPool.add({ task: async () => "hello" }); // OK
108+
relaxedPool.add({ task: async () => 1 }); // OK
109109

110-
// relaxedQueue.all() will return a Promise<unknown[]>, relaxedQueue.results() is an AsyncGenerator<unknown>
110+
// relaxedPool.all() will return a Promise<unknown[]>, relaxedPool.results() is an AsyncGenerator<unknown>
111111
```
112112

113113
## API Documentation

docs/README.md

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
1-
**@aherve/async-queue v1.0.4**
1+
**@aherve/async-pool v1.0.4**
22

33
***
44

5-
# Async Queue
5+
# Async Pool
66

77
Process asynchronous tasks with controlled max concurrency and memory efficiency.
88

9-
![NPM Version](https://img.shields.io/npm/v/%40aherve%2Fasync-queue)
10-
![NPM Downloads](https://img.shields.io/npm/dm/%40aherve%2Fasync-queue)
11-
![NPM License](https://img.shields.io/npm/l/%40aherve%2Fasync-queue)
12-
![npm bundle size](https://img.shields.io/bundlephobia/min/%40aherve%2Fasync-queue)
9+
![NPM Version](https://img.shields.io/npm/v/%40aherve%2Fasync-pool)
10+
![NPM Downloads](https://img.shields.io/npm/dm/%40aherve%2Fasync-pool)
11+
![NPM License](https://img.shields.io/npm/l/%40aherve%2Fasync-pool)
12+
![npm bundle size](https://img.shields.io/bundlephobia/min/%40aherve%2Fasync-pool)
1313

1414
## Features
1515

1616
- **Concurrency Control:** Limit the number of promises running at the same time.
17-
- **Memory Efficiency:** Results are yielded or handled as soon as they are available, so you don't need to store all results in an array.
17+
- **Memory Efficiency:** Can process large numbers of tasks without having to build a large arrays of results.
1818
- **Flexible API:** Supports both async iteration and promise-based consumption.
1919

20+
## Installation
21+
22+
```bash
23+
npm install @aherve/async-pool
24+
```
25+
26+
```typescript
27+
// with TypeScript or ES Modules
28+
import { AsyncPool } from "@aherve/async-pool";
29+
30+
// or with CommonJS
31+
const AsyncPool = require("@aherve/async-pool").AsyncPool;
32+
```
33+
2034
## Usage
2135

2236
### Consume results as a stream
2337
```typescript
24-
const queue = new AsyncQueue<number>() // generic can optionally be used
38+
const pool = new AsyncPool<number>() // generic can optionally be used
2539
.withConcurrency(10)
2640
.withRetries(3); // default number of retries for each task unless specified at task level
2741

28-
// enqueue many tasks
42+
// add many tasks
2943
for (let i = 0; i < 100; i++) {
30-
queue.enqueue({
44+
pool.add({
3145
task: async () => 2 * i,
32-
maxRetries: 3, // optional, will override the queue's default when set
46+
maxRetries: 3, // optional, will override the pool's default when set
3347
});
3448
}
3549

3650
// consume results as a stream, without building a large array of results
3751
let sum = 0;
38-
for await (const res of queue.results()) {
52+
for await (const res of pool.results()) {
3953
sum += res;
4054
}
4155

@@ -52,51 +66,51 @@ const task = async () => {
5266
console.log("hello, world");
5367
};
5468

55-
// create queue and add some tasks
56-
const queue = new AsyncQueue()
69+
// create pool and add some tasks
70+
const pool = new AsyncPool()
5771
.withConcurrency(10)
5872
.withRetries(3)
59-
.enqueue({ task })
60-
.enqueue({ task })
61-
.enqueue({ task });
73+
.add({ task })
74+
.add({ task })
75+
.add({ task });
6276

6377
// wait until all tasks are processed
64-
await queue.waitForTermination();
78+
await pool.waitForTermination();
6579
```
6680

6781
### Promise-based consumption
6882

6983
Similar to `Promise.all`, but with controlled concurrency and builtin retries
7084

7185
```typescript
72-
const queue = new AsyncQueue();
86+
const pool = new AsyncPool();
7387

74-
queue.enqueue({ task: async () => 1 });
75-
queue.enqueue({ task: async () => true });
76-
queue.enqueue({ task: async () => "hello" });
88+
pool.add({ task: async () => 1 });
89+
pool.add({ task: async () => true });
90+
pool.add({ task: async () => "hello" });
7791

78-
const results = await queue.all();
92+
const results = await pool.all();
7993
console.log(results); // [1, true, "hello"], order not guaranteed (especially if retries happened)
8094
```
8195

8296
### Using generic typings
8397

84-
You can specify a generic type for the `AsyncQueue` to enforce type safety on the results of the tasks. If you don't specify a type, it will default to `unknown`, allowing any type of result.
98+
You can specify a generic type for the `AsyncPool` to enforce type safety on the results of the tasks. If you don't specify a type, it will default to `unknown`, allowing any type of result.
8599

86100
```typescript
87-
const typedQueue = new AsyncQueue<string>();
101+
const typedPool = new AsyncPool<string>();
88102

89-
typedQueue.enqueue({ task: async () => "hello" }); // OK
90-
typedQueue.enqueue({ task: async () => 1 }); // ❌ Error: Type 'Promise<number>' is not assignable to type 'Promise<string>'.
103+
typedPool.add({ task: async () => "hello" }); // OK
104+
typedPool.add({ task: async () => 1 }); // ❌ Error: Type 'Promise<number>' is not assignable to type 'Promise<string>'.
91105

92-
// typedQueue.all() will return a Promise<string[]>, typedQueue.results() is an AsyncGenerator<string>
106+
// typedPool.all() will return a Promise<string[]>, typedPool.results() is an AsyncGenerator<string>
93107

94-
const relaxedQueue = new AsyncQueue();
108+
const relaxedPool = new AsyncPool();
95109

96-
relaxedQueue.enqueue({ task: async () => "hello" }); // OK
97-
relaxedQueue.enqueue({ task: async () => 1 }); // OK
110+
relaxedPool.add({ task: async () => "hello" }); // OK
111+
relaxedPool.add({ task: async () => 1 }); // OK
98112

99-
// relaxedQueue.all() will return a Promise<unknown[]>, relaxedQueue.results() is an AsyncGenerator<unknown>
113+
// relaxedPool.all() will return a Promise<unknown[]>, relaxedPool.results() is an AsyncGenerator<unknown>
100114
```
101115

102116
## API Documentation

docs/_media/globals.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
[**@aherve/async-queue v1.0.4**](README.md)
1+
[**@aherve/async-pool v1.0.4**](README.md)
22

33
***
44

5-
# @aherve/async-queue v1.0.4
5+
# @aherve/async-pool v1.0.4
66

77
## Classes
88

9-
- [AsyncQueue](classes/AsyncQueue.md)
9+
- [AsyncPool](classes/AsyncPool.md)
1010

1111
## Interfaces
1212

13-
- [AsyncQueueOptions](interfaces/AsyncQueueOptions.md)
14-
- [AsyncQueueTask](interfaces/AsyncQueueTask.md)
13+
- [AsyncPoolOptions](interfaces/AsyncPoolOptions.md)
14+
- [AsyncPoolTask](interfaces/AsyncPoolTask.md)

0 commit comments

Comments
 (0)