import core = require ( './interfaces' ) ; interface IQueueItem < T extends Function > { active : boolean ; callback : T ; } class CallbackQueue < T extends Function > { private _callbacks : IQueueItem < T > [ ] = [ ] ; add ( callback ) { var _callback = { active : true , callback : callback } ; this . _callbacks . push ( _callback ) ; callback = null ; return { remove : function ( ) { this . remove = function ( ) { } ; _callback . active = false ; _callback = null ; } } ; } drain ( ... args ) { var callbacks = this . _callbacks ; var item ; this . _callbacks = [ ] ; for ( var i = 0 ; i < callbacks . length ; i ++ ) { item = callbacks [ i ] ; if ( item && item . active ) { item . callback . apply ( null , args ) ; } } } } export = CallbackQueue ;