Skip to content

Commit 3ae4811

Browse files
committed
📝 Add 'installation' and 'usage' and example
Signed-off-by: kei-g <km.8k6ce+github@gmail.com>
1 parent 4d77c1d commit 3ae4811

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
**/.travis.yml
77
**/CODE_OF_CONDUCT.md
88
**/build/
9+
**/example.ts
910
**/src/
1011
**/test/
1112
**/tsconfig.json

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,63 @@
22

33
[![coverage][nyc-cov-image]][github-url] [![maintenance][maintenance-image]][npmsio-url] [![quality][quality-image]][npmsio-url]
44

5-
Async Iterable Queue
5+
`async-iterable-queue` - A library for 'Queue' class which implements AsyncIterable\<T\> works on [Node.js](https://nodejs.org/)
6+
7+
## Installation
8+
9+
```shell
10+
npm i async-iterable-queue
11+
```
12+
13+
## Usage
14+
15+
```typescript
16+
import { AsyncIterableQueue } from 'async-iterable-queue'
17+
18+
type Foo = {
19+
id: number
20+
name: string
21+
}
22+
23+
async function example1(queue: AsyncIterableQueue<Foo>): Promise<void> {
24+
console.debug('pushing 123')
25+
await queue.push({
26+
id: 123,
27+
name: 'foo',
28+
})
29+
console.debug('123 has been pushed')
30+
await queue.push({
31+
id: 456,
32+
name: 'bar',
33+
})
34+
console.debug('456 has been pushed')
35+
await queue.push({
36+
id: 789,
37+
name: 'baz',
38+
})
39+
console.debug('789 has been pushed')
40+
await queue.end()
41+
console.debug('\'end\' has been pushed')
42+
}
43+
44+
async function example2(queue: AsyncIterableQueue<Foo>): Promise<void> {
45+
for await (const value of queue)
46+
console.debug(value)
47+
console.debug('all elements have been popped from queue')
48+
}
49+
50+
async function example(): Promise<void> {
51+
console.debug('example for AsyncIterableQueue has begun')
52+
const queue = new AsyncIterableQueue<Foo>()
53+
await Promise.all([
54+
example1(queue),
55+
example2(queue),
56+
])
57+
console.debug('example for AsyncIterableQueue has finished')
58+
}
59+
60+
example()
61+
```
662

763
[depencency-image]:https://img.shields.io/librariesio/release/npm/async-iterable-queue?logo=nodedotjs
864
[dependency-url]:https://npmjs.com/package/async-iterable-queue?activeTab=dependencies

example.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import { AsyncIterableQueue } from './src'
3+
4+
type Foo = {
5+
id: number
6+
name: string
7+
}
8+
9+
async function example1(queue: AsyncIterableQueue<Foo>): Promise<void> {
10+
console.debug('pushing 123')
11+
await queue.push({
12+
id: 123,
13+
name: 'foo',
14+
})
15+
console.debug('123 has been pushed')
16+
await queue.push({
17+
id: 456,
18+
name: 'bar',
19+
})
20+
console.debug('456 has been pushed')
21+
await queue.push({
22+
id: 789,
23+
name: 'baz',
24+
})
25+
console.debug('789 has been pushed')
26+
await queue.end()
27+
console.debug('\'end\' has been pushed')
28+
}
29+
30+
async function example2(queue: AsyncIterableQueue<Foo>): Promise<void> {
31+
for await (const value of queue)
32+
console.debug(value)
33+
console.debug('all elements have been popped from queue')
34+
}
35+
36+
async function example(): Promise<void> {
37+
console.debug('example for AsyncIterableQueue has begun')
38+
const queue = new AsyncIterableQueue<Foo>()
39+
await Promise.all([
40+
example1(queue),
41+
example2(queue),
42+
])
43+
console.debug('example for AsyncIterableQueue has finished')
44+
}
45+
46+
example()

0 commit comments

Comments
 (0)