MCPcopy Create free account
hub / github.com/awslabs/llrt / tee_cancel_algorithm_impl

Method tee_cancel_algorithm_impl

modules/llrt_stream_web/src/readable/stream/tee.rs:472–508  ·  view source on GitHub ↗

Cancel algorithm for tee - handles both branches

(
        ctx: Ctx<'js>,
        objects: ReadableStreamObjects<
            'js,
            impl ReadableStreamController<'js>,
            impl ReadableStreamReader<'js>,
        >,
        reasons

Source from the content-addressed store, hash-verified

470impl<'js> ReadableStream<'js> {
471 // Cancel algorithm for tee - handles both branches
472 fn tee_cancel_algorithm_impl(
473 ctx: Ctx<'js>,
474 objects: ReadableStreamObjects<
475 'js,
476 impl ReadableStreamController<'js>,
477 impl ReadableStreamReader<'js>,
478 >,
479 reasons: [&Rc<OnceCell<Value<'js>>>; 2],
480 cancel_promise: ResolveablePromise<'js>,
481 reason: Value<'js>,
482 branch: usize,
483 ) -> Result<Promise<'js>> {
484 let other = 1 - branch;
485
486 // Set canceled[branch] to true, set reason[branch] to reason
487 reasons[branch]
488 .set(reason.clone())
489 .expect("tee stream already has a cancel reason");
490
491 // If other branch is also canceled
492 if let Some(other_reason) = reasons[other].get().cloned() {
493 // CreateArrayFromList with reasons in correct order
494 let composite_reason = if branch == 0 {
495 List((reason, other_reason))
496 } else {
497 List((other_reason, reason))
498 };
499 let (cancel_result, _) = ReadableStream::readable_stream_cancel(
500 ctx.clone(),
501 objects,
502 composite_reason.into_js(&ctx)?,
503 )?;
504 cancel_promise.resolve(cancel_result)?;
505 }
506
507 Ok(cancel_promise.promise)
508 }
509
510 fn readable_byte_stream_tee(
511 ctx: Ctx<'js>,

Callers

nothing calls this directly

Calls 5

resolveMethod · 0.65
setMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
into_jsMethod · 0.45

Tested by

no test coverage detected