"use strict" ; import { IDisposable } from "./lifecycle" ; export interface IdleDeadline { readonly didTimeout : boolean ; timeRemaining ( ) : number ; } export let runWhenIdle ; /**
 * An implementation of the "idle-until-urgent"-strategy as introduced
 * here: https://philipwalton.com/articles/idle-until-urgent/
 */ export class IdleValue < T > { private readonly _executor : ( ) => void ; private readonly _handle : IDisposable ; private _didRun : boolean = false ; private _value ? : T ; private _error : any ; constructor ( executor ) { this . _executor = ( ) => { try { this . _value = executor ( ) ; } catch ( err ) { this . _error = err ; } finally { this . _didRun = true ; } } ; this . _handle = runWhenIdle ( ( ) => this . _executor ( ) ) ; } dispose ( ) { this . _handle . dispose ( ) ; } getValue ( ) { if ( ! this . _didRun ) { this . _handle . dispose ( ) ; this . _executor ( ) ; } if ( this . _error ) { throw this . _error ; } return this . _value ! ; } }