nl_tokens: The core of the RenderContext object adds the callback to the queue . If the context is waiting ( meaning an async operation is happening ) then the callback will be executed in order once the other operations are complete . If there is no currently executing operation the callback is executed immediately . The value returned from the callback is stored in content for the subsiquent operation . If you return false the queue will pause and the next callback in the queue will not be executed until next () is called . This allows for the guarunteed order of execution while working with async operations . If then () is passed a string instead of a function the string is looked up as a helper method on the event context . ### Example this . get ( # / function () { // initialize the RenderContext // Even though load () executes async the next then () // wont execute until the load finishes this . load ( myfile . txt ) . then ( function ( content ) { // the first argument to then is the content of the // prev operation $ ( #main ) . html ( content ) ; } ) ; } ) ;
pl_tokens: function ( callback ) { if ( ! _isFunction ( callback ) ) { // if a string is passed to then, assume we want to call // a helper on the event context in its context if ( typeof callback === 'string' && <mask> in this . event_context ) { var helper = this . event_context [ callback ] ; callback = function ( content ) { return helper . apply ( this . event_context , [ content ] ) ; } ; } else { return this ; } } var context = this ; if ( this . waiting ) { this . callbacks . push ( callback ) ; } else { this . wait ( ) ; window . setTimeout ( function ( ) { var returned = callback . apply ( context , [ context . content , context . previous_content ] ) ; if ( returned !== false ) { context . next ( returned ) ; } } , 13 ) ; } return this ; }