import { isNil } from 'lodash' ; export class GeneratorExecutor < T = { } > { private prevCall : IteratorResult < unknown , unknown > ; constructor ( private readonly generatorFunc ) { } public next ( ) { const currentCall = this . generatorFunc . next ( isNil ( this . prevCall ) ? undefined : ( this . prevCall . value as any ) ) ; this . prevCall = currentCall ; return currentCall ; } public runTillEnd ( ) { let done = false ; while ( done !== true ) { done = this . next ( ) . done ; } return this . prevCall . value as T ; } }