MCPcopy Index your code
hub / github.com/nodejs/node / testBidirectional

Function testBidirectional

test/parallel/test-stream-iter-duplex.js:23–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21}
22
23async function testBidirectional() {
24 const [channelA, channelB] = duplex();
25
26 // A writes to B, B writes to A concurrently
27 const writeA = (async () => {
28 await channelA.writer.write('A to B');
29 await channelA.close();
30 })();
31
32 const writeB = (async () => {
33 await channelB.writer.write('B to A');
34 await channelB.close();
35 })();
36
37 const readAtB = text(channelB.readable);
38 const readAtA = text(channelA.readable);
39
40 await Promise.all([writeA, writeB]);
41
42 const [dataAtA, dataAtB] = await Promise.all([readAtA, readAtB]);
43
44 assert.strictEqual(dataAtB, 'A to B');
45 assert.strictEqual(dataAtA, 'B to A');
46}
47
48async function testMultipleWrites() {
49 const [channelA, channelB] = duplex({ highWaterMark: 10 });

Callers 1

Calls 5

duplexFunction · 0.85
allMethod · 0.80
closeMethod · 0.65
textFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…