nl_tokens: Function for creating non - iterable suspendable functions .
pl_tokens: function makeAsyncNonIterator ( bodyFunc , config , semaphore ) { // Return a function that executes fn in a fiber and returns a promise of fn's result. return function nonIterable ( ) { // Get all the arguments passed in, as an array. var argsAsArray = new Array ( arguments . length ) ; for ( var i = 0 ; i < argsAsArray . length ; ++ i ) argsAsArray [ i ] = arguments [ i ] ; // Remove concurrency restrictions for nested calls, to avoid race conditions. if ( FiberMgr . isExecutingInFiber ( ) ) this . _semaphore = Semaphore . unlimited ; // Configure the run context. var runContext = new RunContext ( bodyFunc , this , argsAsArray , function ( ) { return semaphore . leave ( ) ; } ) ; if ( config . returnValue !== Config . NONE ) { var resolver = defer ( ) ; runContext . resolver = resolver ; } if ( config . acceptsCallback && argsAsArray . length && _ . isFunction ( argsAsArray [ argsAsArray . length - 1 ] ) ) { var callback = argsAsArray . pop ( ) ; runContext . callback = callback ; } // Execute bodyFunc to completion in a coroutine. For thunks, this is a lazy operation. if ( config . returnValue === Config . THUNK ) { var thunk = function ( done ) { if ( done ) resolver . promise . then ( function ( val ) { return done ( null , val ) ; } , function ( <mask> ) { return done ( err ) ; } ) ; semaphore . enter ( function ( ) { return FiberMgr . create ( ) . run ( runContext ) ; } ) ; } ; } else { semaphore . enter ( function ( ) { return FiberMgr . create ( ) . run ( runContext ) ; } ) ; } // Return the appropriate value. switch ( config . returnValue ) { case Config . PROMISE : return resolver . promise ; case Config . THUNK : return thunk ; case Config . RESULT : return await ( resolver . promise ) ; case Config . NONE : return ; } } ; }