class TasksRunner < T > { private _currentTask : IterableIterator < T > = null ; param { Generator } IterableIterator returns memberOf run ( f ) { if ( this . _currentTask ) { this . _currentTask . return ( ) ; } this . _currentTask = f ( ) ; this . _run ( ) ; return this ; } memberOf stop ( ) { if ( this . _currentTask ) { this . _currentTask . return ( ) ; } } _run ( ) { const it = this . _currentTask ; function run ( args ? ) { try { const result = it . next ( args ) ; if ( result . done ) { return result . value ; } else { return Promise . resolve ( result . value ) . then ( run ) ; } } catch ( error ) { } } run ( ) ; } } export default TasksRunner ;