mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 01:16:15 -04:00
db/DB.js: allow a Promise return instead of callbacks in init()
This commit is contained in:
parent
b0846ded14
commit
3802073695
1 changed files with 17 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue