From cdb0f45c758cab3eb0d4aa46e2361082cc09711c Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Mon, 19 Nov 2018 00:17:12 -0800 Subject: [PATCH 1/2] Handle errors from Mapscii.init() --- main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 3dc09ce..7498c1a 100644 --- a/main.js +++ b/main.js @@ -11,4 +11,7 @@ const Mapscii = require('./src/Mapscii'); const mapscii = new Mapscii(); -mapscii.init(); +mapscii.init().catch((err) => { + console.error('Failed to start MapSCII.'); + console.error(err); +}); From 926a6d0bccd60c07cb9d6036ae38786c8acf65f9 Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Mon, 19 Nov 2018 00:18:05 -0800 Subject: [PATCH 2/2] Use async to simplify Mapscii.init() --- src/Mapscii.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Mapscii.js b/src/Mapscii.js index 9946d55..e9be433 100644 --- a/src/Mapscii.js +++ b/src/Mapscii.js @@ -43,18 +43,15 @@ class Mapscii { config = Object.assign(config, options); } - init() { - return new Promise((resolve) => { - if (!config.headless) { - this._initKeyboard(); - this._initMouse(); - } - this._initTileSource(); - this._initRenderer(); - this._draw(); - this.notify('Welcome to MapSCII! Use your cursors to navigate, a/z to zoom, q to quit.'); - resolve(); - }); + async init() { + if (!config.headless) { + this._initKeyboard(); + this._initMouse(); + } + this._initTileSource(); + this._initRenderer(); + this._draw(); + this.notify('Welcome to MapSCII! Use your cursors to navigate, a/z to zoom, q to quit.'); }