-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
46 lines (40 loc) · 1.01 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { AsyncIterableQueue } from './src'
type Foo = {
id: number
name: string
}
async function example1(queue: AsyncIterableQueue<Foo>): Promise<void> {
console.debug('pushing 123')
await queue.push({
id: 123,
name: 'foo',
})
console.debug('123 has been pushed')
await queue.push({
id: 456,
name: 'bar',
})
console.debug('456 has been pushed')
await queue.push({
id: 789,
name: 'baz',
})
console.debug('789 has been pushed')
await queue.end()
console.debug('\'end\' has been pushed')
}
async function example2(queue: AsyncIterableQueue<Foo>): Promise<void> {
for await (const value of queue)
console.debug(value)
console.debug('all elements have been popped from queue')
}
async function example(): Promise<void> {
console.debug('example for AsyncIterableQueue has begun')
const queue = new AsyncIterableQueue<Foo>()
await Promise.all([
example1(queue),
example2(queue),
])
console.debug('example for AsyncIterableQueue has finished')
}
example()