• Subscribes multiple streams to an AbortSignal, destroying each stream when the signal is aborted.

    If the signal is already aborted, all provided streams are destroyed immediately. Otherwise, a one-time listener is registered to destroy the streams upon abort.

    Returns an unsubscribe function to remove the abort listener allowing proper lifecycle cleanup.

    Parameters

    • signal: AbortSignal

      An optional AbortSignal to observe.

    • ...streams: Destroyable[]

      One or more Node.js streams to destroy when the signal is aborted.

    Returns () => void

    A function that removes the abort event listener. Safe to call multiple times.

    const unsubscribe = subscribeAbortStreams(signal, readable, transform, writable);

    try
    {
    readable.pipe(transform).pipe(writable);
    }
    finally
    {
    unsubscribe();
    }