@@ -270,7 +270,7 @@ class EmberApp {
270270 let res = options . response ;
271271 let html = options . html || this . html ;
272272 let disableShoebox = options . disableShoebox || false ;
273- let destroyAppInstanceInMs = options . destroyAppInstanceInMs ;
273+ let destroyAppInstanceInMs = parseInt ( options . destroyAppInstanceInMs , 10 ) ;
274274
275275 let shouldRender = ( options . shouldRender !== undefined ) ? options . shouldRender : true ;
276276 let bootOptions = buildBootOptions ( shouldRender ) ;
@@ -289,23 +289,17 @@ class EmberApp {
289289 } ) ;
290290
291291 let destroyAppInstanceTimer ;
292- if ( parseInt ( destroyAppInstanceInMs , 10 ) > 0 ) {
292+ if ( destroyAppInstanceInMs > 0 ) {
293293 // start a timer to destroy the appInstance forcefully in the given ms.
294294 // This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
295295 destroyAppInstanceTimer = setTimeout ( function ( ) {
296- if ( instance && ! result . instanceDestroyed ) {
297- result . instanceDestroyed = true ;
296+ if ( result . _destroyAppInstance ( ) ) {
298297 result . error = new Error ( 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms' ) ;
299- instance . destroy ( ) ;
300298 }
301299 } , destroyAppInstanceInMs ) ;
302300 }
303301
304- let instance ;
305302 return this . visitRoute ( path , fastbootInfo , bootOptions , result )
306- . then ( appInstance => {
307- instance = appInstance ;
308- } )
309303 . then ( ( ) => {
310304 if ( ! disableShoebox ) {
311305 // if shoebox is not disabled, then create the shoebox and send API data
@@ -315,10 +309,7 @@ class EmberApp {
315309 . catch ( error => result . error = error )
316310 . then ( ( ) => result . _finalize ( ) )
317311 . finally ( ( ) => {
318- if ( instance && ! result . instanceDestroyed ) {
319- result . instanceDestroyed = true ;
320- instance . destroy ( ) ;
321-
312+ if ( result . _destroyAppInstance ( ) ) {
322313 if ( destroyAppInstanceTimer ) {
323314 clearTimeout ( destroyAppInstanceTimer ) ;
324315 }
0 commit comments