@@ -266,7 +266,7 @@ class EmberApp {
266266 let res = options . response ;
267267 let html = options . html || this . html ;
268268 let disableShoebox = options . disableShoebox || false ;
269- let destroyAppInstanceInMs = options . destroyAppInstanceInMs ;
269+ let destroyAppInstanceInMs = parseInt ( options . destroyAppInstanceInMs , 10 ) ;
270270
271271 let shouldRender = ( options . shouldRender !== undefined ) ? options . shouldRender : true ;
272272 let bootOptions = buildBootOptions ( shouldRender ) ;
@@ -285,23 +285,17 @@ class EmberApp {
285285 } ) ;
286286
287287 let destroyAppInstanceTimer ;
288- if ( parseInt ( destroyAppInstanceInMs , 10 ) > 0 ) {
288+ if ( destroyAppInstanceInMs > 0 ) {
289289 // start a timer to destroy the appInstance forcefully in the given ms.
290290 // This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
291291 destroyAppInstanceTimer = setTimeout ( function ( ) {
292- if ( instance && ! result . instanceDestroyed ) {
293- result . instanceDestroyed = true ;
292+ if ( result . _destroyAppInstance ( ) ) {
294293 result . error = new Error ( 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms' ) ;
295- instance . destroy ( ) ;
296294 }
297295 } , destroyAppInstanceInMs ) ;
298296 }
299297
300- let instance ;
301298 return this . visitRoute ( path , fastbootInfo , bootOptions , result )
302- . then ( appInstance => {
303- instance = appInstance ;
304- } )
305299 . then ( ( ) => {
306300 if ( ! disableShoebox ) {
307301 // if shoebox is not disabled, then create the shoebox and send API data
@@ -311,10 +305,7 @@ class EmberApp {
311305 . catch ( error => result . error = error )
312306 . then ( ( ) => result . _finalize ( ) )
313307 . finally ( ( ) => {
314- if ( instance && ! result . instanceDestroyed ) {
315- result . instanceDestroyed = true ;
316- instance . destroy ( ) ;
317-
308+ if ( result . _destroyAppInstance ( ) ) {
318309 if ( destroyAppInstanceTimer ) {
319310 clearTimeout ( destroyAppInstanceTimer ) ;
320311 }
0 commit comments