Skip to content

Commit 941a670

Browse files
authored
Merge pull request #410 from autonomys/duplicate-streams
feat: safe fork stream method for asynchronous pkg
2 parents d96f3d7 + dab1792 commit 941a670

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

packages/utility/asynchronous/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
"types": "./dist/index.d.ts",
2323
"devDependencies": {
2424
"@types/jest": "^29.5.14",
25+
"@types/stream-fork": "^1",
2526
"eslint": "^9.25.1",
2627
"interface-store": "^6.0.2",
2728
"jest": "^29.7.0",
2829
"prettier": "^3.5.3",
2930
"ts-jest": "^29.3.1",
3031
"typescript": "^5.8.3"
3132
},
32-
"gitHead": "ef4c21d683cad697f7015e52becd399a8ca2ed84"
33+
"gitHead": "ef4c21d683cad697f7015e52becd399a8ca2ed84",
34+
"dependencies": {
35+
"stream-fork": "^1.0.5"
36+
}
3337
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './asyncGenerators'
22
export * from './concurrency'
3+
export * from './streams'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PassThrough, Readable } from 'stream'
2+
import streamFork from 'stream-fork'
3+
4+
export async function forkStream(stream: Readable): Promise<[Readable, Readable]> {
5+
const passThrough1 = new PassThrough()
6+
const passThrough2 = new PassThrough()
7+
const writable = streamFork.fork([passThrough1, passThrough2])
8+
9+
stream.pipe(writable)
10+
11+
return [passThrough1, passThrough2]
12+
}

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ __metadata:
3434
resolution: "@autonomys/asynchronous@workspace:packages/utility/asynchronous"
3535
dependencies:
3636
"@types/jest": "npm:^29.5.14"
37+
"@types/stream-fork": "npm:^1"
3738
eslint: "npm:^9.25.1"
3839
interface-store: "npm:^6.0.2"
3940
jest: "npm:^29.7.0"
4041
prettier: "npm:^3.5.3"
42+
stream-fork: "npm:^1.0.5"
4143
ts-jest: "npm:^29.3.1"
4244
typescript: "npm:^5.8.3"
4345
languageName: unknown
@@ -7768,6 +7770,15 @@ __metadata:
77687770
languageName: node
77697771
linkType: hard
77707772

7773+
"@types/stream-fork@npm:^1":
7774+
version: 1.0.5
7775+
resolution: "@types/stream-fork@npm:1.0.5"
7776+
dependencies:
7777+
"@types/node": "npm:*"
7778+
checksum: 10c0/139d047cccfcbe6ac23be7a7d025b0ffbb885a0075b19248f2b7bed1becc6647180196c50152cafecb6cba52d7d1e4507d2beb2f632500bc426c06d86797fce1
7779+
languageName: node
7780+
linkType: hard
7781+
77717782
"@types/unist@npm:^2.0.0":
77727783
version: 2.0.11
77737784
resolution: "@types/unist@npm:2.0.11"
@@ -20935,6 +20946,13 @@ __metadata:
2093520946
languageName: node
2093620947
linkType: hard
2093720948

20949+
"stream-fork@npm:^1.0.5":
20950+
version: 1.0.5
20951+
resolution: "stream-fork@npm:1.0.5"
20952+
checksum: 10c0/b13a88550276d80ddaccb17be3e4e47e69f275a86b8f74f763125b02d699293ef41b52b456ed0897c21b38f4e895b7d4606495dc9411ab006050047476933bdf
20953+
languageName: node
20954+
linkType: hard
20955+
2093820956
"stream-shift@npm:^1.0.0":
2093920957
version: 1.0.3
2094020958
resolution: "stream-shift@npm:1.0.3"

0 commit comments

Comments
 (0)