import { Resolvable , Promise } from '../promise' ; export type LockHandler < TResult > = ( ) => Resolvable < TResult > ; /**
 * `Lock` class is a useful helper that can act as a simple task queue.
 */ export class Lock { private _promise = Promise . void ; param handler return queue < TResult > ( handler ) { let promise = this . _promise . then ( handler ) ; this . _promise = promise . void . fail ( reason => undefined ) ; return promise ; } param handler return try < TResult > ( handler ) { if ( this . _promise . pending ) { return < Promise < any > > this . _promise ; } else { return this . queue ( handler ) ; } } /**
     * (get) A function that binds `queue` method with current instance.
     */ get queuer ( ) : < TResult > ( handler : LockHandler < TResult > ) => Promise < TResult > { return this . queue . bind ( this ) ; } /**
     * (get) A function that binds `try` method with current instance.
     */ get trier ( ) : < TResult > ( handler : LockHandler < TResult > ) => Promise < TResult > { return this . try . bind ( this ) ; } }