/**
 * Class used to signify that something was aborted. Useful for applications to conditionally handle
 * this type of error differently than other errors.
 */ export class AbortError extends Error { constructor ( message = 'Aborted' ) { super ( message ) ; this . message = message ; this . name = 'AbortError' ; } } param signal export function toPromise ( signal ) { return new Promise ( ( resolve , reject ) => { if ( signal . aborted ) reject ( new AbortError ( ) ) ; const abortHandler = ( ) => { signal . removeEventListener ( 'abort' , abortHandler ) ; reject ( new AbortError ( ) ) ; } ; signal . addEventListener ( 'abort' , abortHandler ) ; } ) ; } param signals export function getCombinedSignal ( signals ) { const controller = new AbortController ( ) ; if ( signals . some ( ( signal ) => signal . aborted ) ) { controller . abort ( ) ; } else { const promises = signals . map ( ( signal ) => toPromise ( signal ) ) ; Promise . race ( promises ) . catch ( ( ) => controller . abort ( ) ) ; } return controller . signal ; }