db/DB.js: allow a Promise return instead of callbacks in init()

pull/3559/head
Ray Bellis 2019-01-18 13:48:46 +00:00
parent b0846ded14
commit 3802073695
1 changed files with 17 additions and 1 deletions

View File

@ -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");
}
}