From 3802073695166bc0892e0956e69aa5ab93a21752 Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Fri, 18 Jan 2019 13:48:46 +0000 Subject: [PATCH] db/DB.js: allow a Promise return instead of callbacks in init() --- src/node/db/DB.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/node/db/DB.js b/src/node/db/DB.js index 93848b1bd..fa94259b5 100644 --- a/src/node/db/DB.js +++ b/src/node/db/DB.js @@ -35,7 +35,7 @@ exports.db = null; * Initalizes the database with the settings provided by the settings module * @param {Function} callback */ -exports.init = function(callback) { +function init(callback) { // initalize the database async db.init(function(err) { if (err) { @@ -50,3 +50,19 @@ exports.init = function(callback) { } }); } + +/** + * Initalizes the database with the settings provided by the settings module + * If the callback is not supplied a Promise is returned instead. + * @param {Function} callback + */ +exports.init = function(callback) +{ + if (callback === undefined) { + return new Promise(resolve => init(resolve)); + } else if (typeof callback === "function") { + init(callback); + } else { + throw new TypeError("DB.init callback parameter"); + } +}