@@ -270,7 +270,7 @@ class EmberApp {
270
270
let res = options . response ;
271
271
let html = options . html || this . html ;
272
272
let disableShoebox = options . disableShoebox || false ;
273
- let destroyAppInstanceInMs = options . destroyAppInstanceInMs ;
273
+ let destroyAppInstanceInMs = parseInt ( options . destroyAppInstanceInMs , 10 ) ;
274
274
275
275
let shouldRender = ( options . shouldRender !== undefined ) ? options . shouldRender : true ;
276
276
let bootOptions = buildBootOptions ( shouldRender ) ;
@@ -289,23 +289,17 @@ class EmberApp {
289
289
} ) ;
290
290
291
291
let destroyAppInstanceTimer ;
292
- if ( parseInt ( destroyAppInstanceInMs , 10 ) > 0 ) {
292
+ if ( destroyAppInstanceInMs > 0 ) {
293
293
// start a timer to destroy the appInstance forcefully in the given ms.
294
294
// This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
295
295
destroyAppInstanceTimer = setTimeout ( function ( ) {
296
- if ( instance && ! result . instanceDestroyed ) {
297
- result . instanceDestroyed = true ;
296
+ if ( result . _destroyAppInstance ( ) ) {
298
297
result . error = new Error ( 'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms' ) ;
299
- instance . destroy ( ) ;
300
298
}
301
299
} , destroyAppInstanceInMs ) ;
302
300
}
303
301
304
- let instance ;
305
302
return this . visitRoute ( path , fastbootInfo , bootOptions , result )
306
- . then ( appInstance => {
307
- instance = appInstance ;
308
- } )
309
303
. then ( ( ) => {
310
304
if ( ! disableShoebox ) {
311
305
// if shoebox is not disabled, then create the shoebox and send API data
@@ -315,10 +309,7 @@ class EmberApp {
315
309
. catch ( error => result . error = error )
316
310
. then ( ( ) => result . _finalize ( ) )
317
311
. finally ( ( ) => {
318
- if ( instance && ! result . instanceDestroyed ) {
319
- result . instanceDestroyed = true ;
320
- instance . destroy ( ) ;
321
-
312
+ if ( result . _destroyAppInstance ( ) ) {
322
313
if ( destroyAppInstanceTimer ) {
323
314
clearTimeout ( destroyAppInstanceTimer ) ;
324
315
}
0 commit comments