Skip to content

Commit da6bbbb

Browse files
author
Robert Jackson
committed
Refactor visitRoute to an async function.
1 parent 1ff2b24 commit da6bbbb

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/ember-app.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class EmberApp {
186186
* Create the ember application in the sandbox.
187187
*
188188
*/
189-
createEmberApp(sandbox) {
189+
createEmberApp(sandbox) {
190190
// Retrieve the application factory from within the sandbox
191191
let AppFactory = sandbox.run(function(ctx) {
192192
return ctx.require('~fastboot/app-factory');
@@ -288,7 +288,7 @@ class EmberApp {
288288
* @param {ClientResponse}
289289
* @returns {Promise<Result>} result
290290
*/
291-
visit(path, options) {
291+
async visit(path, options) {
292292
let req = options.request;
293293
let res = options.response;
294294
let html = options.html || this.html;
@@ -319,22 +319,27 @@ class EmberApp {
319319
}, destroyAppInstanceInMs);
320320
}
321321

322-
return this.visitRoute(path, fastbootInfo, bootOptions, result)
323-
.then(() => {
324-
if (!disableShoebox) {
325-
// if shoebox is not disabled, then create the shoebox and send API data
326-
createShoebox(doc, fastbootInfo);
327-
}
328-
})
329-
.catch(error => (result.error = error))
330-
.then(() => result._finalize())
331-
.finally(() => {
332-
if (result._destroyAppInstance()) {
333-
if (destroyAppInstanceTimer) {
334-
clearTimeout(destroyAppInstanceTimer);
335-
}
322+
try {
323+
await this.visitRoute(path, fastbootInfo, bootOptions, result);
324+
325+
if (!disableShoebox) {
326+
// if shoebox is not disabled, then create the shoebox and send API data
327+
createShoebox(doc, fastbootInfo);
328+
}
329+
330+
result._finalize();
331+
} catch (error) {
332+
// eslint-disable-next-line require-atomic-updates
333+
result.error = error;
334+
} finally {
335+
if (result._destroyAppInstance()) {
336+
if (destroyAppInstanceTimer) {
337+
clearTimeout(destroyAppInstanceTimer);
336338
}
337-
});
339+
}
340+
}
341+
342+
return result;
338343
}
339344

340345
/**

src/sandbox.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const chalk = require('chalk');
44
const vm = require('vm');
55
const sourceMapSupport = require('source-map-support');
66

7-
87
module.exports = class Sandbox {
98
constructor(globals) {
109
this.globals = globals;

0 commit comments

Comments
 (0)