Skip to content

Commit d37aa4a

Browse files
committed
moved app instance destroy logic to result._destroyAppInstance
1 parent 257cc5e commit d37aa4a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/ember-app.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/result.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const HTMLSerializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
1111
class Result {
1212
constructor(options) {
1313
this.instanceBooted = false;
14-
this.instanceDestroyed = false;
14+
this._instanceDestroyed = false;
1515
this._doc = options.doc;
1616
this._html = options.html;
1717
this._fastbootInfo = options.fastbootInfo;
@@ -97,6 +97,15 @@ class Result {
9797
}
9898
}
9999

100+
_destroyAppInstance() {
101+
if (this.instance && !this._instanceDestroyed) {
102+
this._instanceDestroyed = true;
103+
this.instance.destroy();
104+
return true;
105+
}
106+
return false;
107+
}
108+
100109
_finalizeHTML() {
101110
let head = this._doc.head;
102111
let body = this._doc.body;

0 commit comments

Comments
 (0)