license import { BehaviorSubject , Subscription } from 'rxjs' ; /** Represents the status of auto change detection. */ export interface AutoChangeDetectionStatus { /** Whether auto change detection is disabled. */ isDisabled : boolean ; /**
     * An optional callback, if present it indicates that change detection should be run immediately,
     * while handling the status change. The callback should then be called as soon as change
     * detection is done.
     */ onDetectChangesNow ? : ( ) => void ; } /** Subject used to dispatch and listen for changes to the auto change detection status . */ const autoChangeDetectionSubject = new BehaviorSubject < AutoChangeDetectionStatus > ( { isDisabled : false , } ) ; /** The current subscription to `autoChangeDetectionSubject`. */ let autoChangeDetectionSubscription ; param status function defaultAutoChangeDetectionHandler ( status ) { status . onDetectChangesNow ?. ( ) ; } param handler export function handleAutoChangeDetectionStatus ( handler ) { stopHandlingAutoChangeDetectionStatus ( ) ; autoChangeDetectionSubscription = autoChangeDetectionSubject . subscribe ( handler ) ; } /** Allows a `HarnessEnvironment` to stop handling auto change detection status changes. */ export function stopHandlingAutoChangeDetectionStatus ( ) { autoChangeDetectionSubscription ?. unsubscribe ( ) ; autoChangeDetectionSubscription = null ; } param fn param triggerBeforeAndAfter return async function batchChangeDetection < T > ( fn , triggerBeforeAndAfter ) { if ( autoChangeDetectionSubject . getValue ( ) . isDisabled ) { return await fn ( ) ; } if ( ! autoChangeDetectionSubscription ) { handleAutoChangeDetectionStatus ( defaultAutoChangeDetectionHandler ) ; } if ( triggerBeforeAndAfter ) { await new Promise ( resolve => autoChangeDetectionSubject . next ( { isDisabled : true , onDetectChangesNow : resolve as ( ) => void , } ) ) ; try { return await fn ( ) ; } finally { await new Promise ( resolve => autoChangeDetectionSubject . next ( { isDisabled : false , onDetectChangesNow : resolve as ( ) => void , } ) ) ; } } else { autoChangeDetectionSubject . next ( { isDisabled : true } ) ; try { return await fn ( ) ; } finally { autoChangeDetectionSubject . next ( { isDisabled : false } ) ; } } } param fn return export async function manualChangeDetection < T > ( fn ) { return batchChangeDetection ( fn , false ) ; } param values return export function parallel < T1 , T2 , T3 , T4 , T5 > ( values ) ; param values return export function parallel < T1 , T2 , T3 , T4 > ( values ) ; param values return export function parallel < T1 , T2 , T3 > ( values ) ; param values return export function parallel < T1 , T2 > ( values ) ; param values return export function parallel < T > ( values ) ; param values return export async function parallel < T > ( values ) { return batchChangeDetection ( ( ) => Promise . all ( values ( ) ) , true ) ; }