Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4451167
test_readable_stream_tee_object_chunk.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_readable_stream_tee_object_chunk.cjs
View Options
function assert(condition, message) {
if (!condition) throw new Error(message);
}
async function main() {
const chunk = {
label: 'alpha',
fn() {
return 'ok';
},
};
const source = new ReadableStream({
start(controller) {
controller.enqueue(chunk);
controller.close();
},
});
const [branch1, branch2] = source.tee();
const reader1 = branch1.getReader();
const reader2 = branch2.getReader();
const [{ done: done1, value: value1 }, { done: done2, value: value2 }] =
await Promise.all([reader1.read(), reader2.read()]);
assert(done1 === false, 'branch1 should receive a chunk');
assert(done2 === false, 'branch2 should receive a chunk');
assert(value1 === chunk, 'branch1 should receive the original chunk object');
assert(value2 === chunk, 'branch2 should receive the original chunk object');
assert(value1 === value2, 'tee branches should share the same chunk reference');
assert(typeof value2.fn === 'function', 'function-valued chunk properties should survive tee');
assert(value2.fn() === 'ok', 'function-valued chunk should remain callable');
console.log('readable stream tee preserves object chunks without cloning');
}
main().catch((err) => {
console.error(err && err.stack ? err.stack : String(err));
throw err;
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, May 2, 12:47 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
544294
Default Alt Text
test_readable_stream_tee_object_chunk.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment