db/DB.js: allow a Promise return instead of callbacks in init()
parent
b0846ded14
commit
3802073695
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue