Skip to content

Commit c60c8c8

Browse files
authored
Merge pull request #148 from bekzod/move-destroy
moved app instance destroy logic to `result._destroyAppInstance`
2 parents d5f7c37 + d37aa4a commit c60c8c8

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
@@ -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
}

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)