ReadableStream.tee() makes two branches from one source, but it does not make two independent sources. If one branch cancels while the other keeps reading, the underlying source normally continues and the first cancellation promise may remain pending. The decisive evidence is the terminal path of both branches and the source, not the first branch to finish its local job.
This specialist guide belongs to the Websites root. It also connects to The Gold Standard of Education | Learning That Transfers into Life and the How X Works hub. The worked cases are original teaching examples; their values and event logs are stated so each conclusion can be checked.
eduKateSG · Websites
Find your next learning step
Begin with the original stream lock and the shared pull path. Then trace natural closure, one-branch cancellation, two-branch cancellation, errors and unequal reading pace. The later chapters distinguish default and byte streams, show where object sharing matters and end with a complete terminal-path receipt.
ROUTE 1 · CHAPTERS 1–3
Build the first model
Name the input, state, conversion or predicate before following user-visible results.
ROUTE 2 · CHAPTERS 4–5
Trace the decisive branch
Work the accepted path and the nearest boundary case with original examples.
ROUTE 3 · CHAPTERS 6–8
Change one premise
Rebuild the mechanism when state, value, realm, timing or object kind changes.
ROUTE 4 · CHAPTERS 9–10
Handle limits and failures
Keep abrupt completion, availability and application limits visible.
ROUTE 5 · CHAPTERS 11–12
Verify and explain
Use a decisive fixture, changed-context check and concise final account.
Chapter contents
Build the first model · Chapters 1–3
1. Lock the original and create two branches
Trace the decisive branch · Chapters 4–5
Change one premise · Chapters 6–8
6. Combine two branch cancellation reasons
Handle limits and failures · Chapters 9–10
Verify and explain · Chapters 11–12
CHAPTER 1 OF 12 · Build the first model
1. Lock the original and create two branches
The short answer is that calling tee locks the original stream and returns two branch streams fed by coordinated reads from that source. Chapter 1 focuses on lock the original and create two branches. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. create a source that logs start, pull and cancel; call tee, confirm the original is locked, then acquire one reader for each branch before releasing any chunks. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for lock the original and create two branches is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. try to acquire a reader from the original after tee; the changed fact is its locked state, so the attempted access fails before any source pull. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: tee does not copy the underlying source object or leave the original available for a third consumer. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. assert original.locked, branch reader acquisition and the exact count of source pulls. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of lock the original and create two branches should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 2 OF 12 · Build the first model
2. Follow one source read into both branches
The short answer is that a source chunk is distributed to both active branches by the tee algorithm even though the source is read once. Chapter 2 focuses on follow one source read into both branches. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. enqueue the labelled value {n:1}, issue a read on each branch and show one source production event followed by two branch results. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for follow one source read into both branches is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. read branch one early and delay branch two; the second result still comes from the coordinated source read rather than a second production of n:1. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: two branch results do not prove two independent fetches or two calls to an application producer. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. give source chunks stable sequence labels and compare production count with each branch’s received sequence. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of follow one source read into both branches should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 3 OF 12 · Build the first model
3. Distinguish default chunks from byte clones
The short answer is that default-stream tee can expose the same object chunk to both branches, while byte-stream tee has cloning rules for byte data. Chapter 3 focuses on distinguish default chunks from byte clones. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. enqueue a mutable object on a default stream, read it from both branches and compare identity; then run a byte stream fixture and compare buffers and byte contents. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for distinguish default chunks from byte clones is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. mutate the default object through branch one before examining branch two; shared identity can make the mutation visible even though branch queues are distinct. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: tee is not a general deep-cloning operation, and object sharing must not be inferred for the byte-stream algorithm. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. test identity separately from value equality and label the source as default or byte before interpreting the result. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of distinguish default chunks from byte clones should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 4 OF 12 · Trace the decisive branch
4. Cancel one branch and keep the source alive
The short answer is that when only one branch cancels, the shared underlying stream is not normally canceled while the other branch remains active. Chapter 4 focuses on cancel one branch and keep the source alive. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. cancel branch one with ‘preview complete’, keep the returned promise, then read two more chunks and a close from branch two while logging the source cancel hook. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for cancel one branch and keep the source alive is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. instead of allowing branch two to close naturally, cancel it later; the source then receives the combined branch reasons and the first cancel promise can settle. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: canceling a branch is not the same as synchronously canceling the source, and the cancel promise may intentionally remain pending. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. check the first promise after branch-one cancellation, source cancel-call count and the remaining branch’s terminal event. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of cancel one branch and keep the source alive should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 5 OF 12 · Trace the decisive branch
5. Let the other branch reach natural close
The short answer is that if the source closes while the other branch remains active, the canceled branch’s pending cancellation can resolve without invoking underlying cancellation. Chapter 5 focuses on let the other branch reach natural close. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. cancel branch one, let branch two read the source’s final chunk and done:true, then record the first cancel promise resolving and a zero source-cancel count. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for let the other branch reach natural close is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. make the source error instead of close; both branch terminal observations change and the pending cancellation follows the error path. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: natural source completion resolves coordination without inventing a cancellation reason for a source that already ended. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. assert the exact final chunk, done result, branch closed promises, cancellation settlement and absence of the source cancel hook. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of let the other branch reach natural close should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
The short answer is that after both branches cancel, the tee algorithm cancels the original with a composite value containing the two reasons in branch order. Chapter 6 focuses on combine two branch cancellation reasons. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. cancel branch two with ‘archive stopped’ and branch one with ‘preview stopped’; inspect the source cancel argument and branch-promise settlements. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for combine two branch cancellation reasons is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. reverse the temporal order while retaining branch labels; the composite positions still correspond to branch one and branch two rather than simply arrival order. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: the source reason is a structured pair for this algorithm, not a single winner chosen by timing. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. compare deep values and branch positions, and avoid stringifying away arrays, errors or object reasons. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of combine two branch cancellation reasons should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
The short answer is that an error in the original propagates to active branches, while an orderly close lets their queued data drain before done. Chapter 7 focuses on trace source error and branch closure. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. enqueue one value and then error with a controlled object; read each branch’s prefix and capture the rejection from the next read. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for trace source error and branch closure is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. close after the same prefix; the corresponding next reads now fulfill with done:true and no cancellation hook runs. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: an empty branch queue at one moment cannot tell whether the source will close, error or produce later. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. assert the successful prefix and terminal kind independently for both branches. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of trace source error and branch closure should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
The short answer is that tee coordinates a shared source but can accumulate data for a slower branch, so one fast consumer does not impose complete backpressure on the source for both branches. Chapter 8 focuses on account for unequal reading pace. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. read ten numbered chunks rapidly from branch one while branch two reads only the first; count produced chunks and the unconsumed sequence expected for branch two. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for account for unequal reading pace is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. alternate reads evenly; the source sequence is unchanged but the backlog evidence and memory risk differ. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: the public API does not expose a portable branch queue length meter, so tests must use bounded fixtures and source logs rather than unsupported internals. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. bound production, count each delivered label and stop before using the example as an unbounded memory benchmark. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of account for unequal reading pace should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 9 OF 12 · Handle limits and failures
9. Trace byte-stream readers carefully
The short answer is that byte-stream tee coordinates default and BYOB reading modes and clones byte chunks where the algorithm requires separation. Chapter 9 focuses on trace byte-stream readers carefully. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. construct a byte source, read branch one with a BYOB reader and branch two with a default reader, and record view lengths, offsets and contents. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for trace byte-stream readers carefully is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. release the BYOB reader and acquire a default reader for later data; reader mode changes, but the branch still belongs to the same tee relationship. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: BYOB view fulfillment and underlying buffer state require byte-stream reasoning; default-stream object-identity lessons do not transfer directly. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. record buffer identity, byteOffset, byteLength, returned view and contents for every read. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of trace byte-stream readers carefully should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
CHAPTER 10 OF 12 · Handle limits and failures
10. Avoid accidental cross-branch mutation
The short answer is that application code should not assume default-stream branch chunks are isolated when those chunks are mutable objects. Chapter 10 focuses on avoid accidental cross-branch mutation. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. send a frozen record or immutable byte representation to both consumers and compare with a mutable object whose nested field is changed by branch one. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for avoid accidental cross-branch mutation is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. clone at the producer before enqueueing a separate representation; this changes the application’s data model, not the tee algorithm itself. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: JSON cloning is not a universal substitute because it changes supported values and semantics. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. use an identity assertion and a deliberate mutation fixture before deciding whether application-level copying is required. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of avoid accidental cross-branch mutation should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
The short answer is that a reliable fan-out defines each consumer’s stop condition, ownership of cancellation and acceptable backlog before tee is introduced. Chapter 11 focuses on design a safe production fan-out. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. model a preview consumer that may stop after five chunks and an archive consumer that must reach natural close; state why preview cancellation must not abort the archive. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for design a safe production fan-out is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. change the archive to an optional consumer; with both branches allowed to cancel, the source cancel hook now becomes part of the required cleanup contract. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: tee alone does not provide replay, durable queues, independent retry or unbounded slow-consumer safety. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. write branch responsibilities and terminal actions beside the code, then test every permitted pair of terminal paths. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of design a safe production fan-out should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
The short answer is that a complete receipt reports the source terminal event, both branch terminal events, both cancellation reasons and every pending cancellation promise. Chapter 12 focuses on build a two-branch terminal receipt. Begin with keep one source ledger and two branch ledgers, recording reads, cancellation reasons, pending cancellation promises and the source’s terminal event. Writing those facts first prevents a familiar label or final summary value from replacing the mechanism or measurement basis that actually decides the result.
Worked example. run three bounded cases: one cancel plus natural close, two cancels, and source error; publish the ordered log and expected composite reason. Treat every stated value as part of a controlled teaching fixture. Record the starting state before the operation, then record each conversion, selection, calculation, check or state transition in order. If a prerequisite fails, stop the trace there rather than inferring later effects from the usual path.
A useful first-principles question for build a two-branch terminal receipt is: what must already be true before this step can run? Use the rule above to separate the input contract from the result. Follow object identity, state and returned value independently. Two branches can print similar data while differing in ownership, timing, brand or future capability.
Now change exactly one premise. swap which branch finishes first while keeping the same source data; predict which promises wait and verify the new trace. Recalculate the trace from the changed fact rather than editing the old conclusion. Name the earliest event that differs, carry that difference through the remaining steps, and say which observations stay the same because their prerequisites did not change.
The main limit is this: the receipt proves the stated fixture and ordering constraints, not identical task timing across engines. Keep language semantics separate from processor strategy, host scheduling, browser support, trust policy and the meaning assigned by an application. A focused example can establish the stated mechanism without pretending to settle those broader questions.
Practical evidence check. store source code, branch labels, operation order, expected prefixes and terminal assertions together. Capture the reported values and failure conditions, but also preserve the calculation or event trail that led to them. A check that asserts only the last number or label can pass even when an earlier selection, conversion, grouping, state change or measurement basis was wrong.
A concise final explanation of build a two-branch terminal receipt should state the starting state, the governing rule, the ordered outcome and one boundary. It should not depend on a screenshot, one software message or an unstated assumption. That form is short enough for revision and precise enough for a reproducible technical note.
Contents · Previous chapter · Return to the Websites subject guide
Frequently asked questions
Does canceling one tee branch cancel the original stream?
Usually not while the other branch remains active. The other branch may continue reading until it closes, errors or also cancels.
Why is branch.cancel() still pending?
The tee algorithm may need the other branch’s terminal outcome before it can settle shared cancellation coordination.
What reason reaches the source if both branches cancel?
The underlying cancellation receives a composite containing the two branch reasons in branch order.
Are object chunks copied for both branches?
Do not assume that for a default stream. Mutable object identity can be shared. Byte-stream tee has separate byte-cloning rules.
Can one slow branch build a backlog?
Yes. Use bounded sources and explicit consumer policy; tee is not a durable independent queue for each consumer.
Continue through the verified reading routes
Start with the wider system
The Gold Standard of Websites · The Gold Standard of Education | Learning That Transfers into Life · How X Works hub
Compare the closest mechanisms
The Gold Standard of Websites | Converting Async Iterables with ReadableStream.from Without Losing Cancellation · The Gold Standard of Websites | Separating BYOB Read Requests from the Readable Byte Stream Queue · The Gold Standard of Websites | Separating a Locked Response Body from a Disturbed Response Body · The Gold Standard of Websites | Separating CompressionStream Flush Completion from a Writable Close · The Gold Standard of Websites | Tracing ReadableStream tee Cancellation When One Branch Finishes First · The Gold Standard of Websites | Separating TransformStream Backpressure from Writable Write Completion
Choose the next lesson by reader job
Use the subject root to move from this focused mechanism to the next verified question. Follow a specialist link when its preconditions match your code; return to the wider hub when the next task belongs to a different system.
Authoritative sources and evidence checks
WHATWG Streams — tee a readable stream · WHATWG Streams — ReadableStream tee method · WHATWG Streams — tee a readable byte stream · WHATWG Streams — cancellation
The algorithms and terminal cases follow the WHATWG Streams Living Standard. The worked examples use explicit sources and controlled reads so that branch-local completion is not mistaken for cancellation of the shared underlying source.