bin/rebuildPad.js: Fix sequencing of asynchronous functions

pull/4656/head
Richard Hansen 2021-01-17 04:19:02 -05:00 committed by John McLear
parent 69efd16a6d
commit 72c2abab8d
1 changed files with 9 additions and 5 deletions

View File

@ -45,9 +45,14 @@ async.series([
throw new Error('Cannot create a pad with that id as it is invalid'); throw new Error('Cannot create a pad with that id as it is invalid');
} }
util.callbackify(PadManager.doesPadExist)(newPadId, (err, exists) => { util.callbackify(PadManager.doesPadExist)(newPadId, (err, exists) => {
if (err != null) return callback(err);
if (exists) throw new Error('Cannot create a pad with that id as it already exists'); if (exists) throw new Error('Cannot create a pad with that id as it already exists');
callback();
}); });
},
(callback) => {
util.callbackify(PadManager.getPad)(padId, (err, pad) => { util.callbackify(PadManager.getPad)(padId, (err, pad) => {
if (err) return callback(err);
oldPad = pad; oldPad = pad;
newPad = new Pad(newPadId); newPad = new Pad(newPadId);
callback(); callback();
@ -102,12 +107,11 @@ async.series([
newPad.savedRevisions = newSavedRevisions; newPad.savedRevisions = newSavedRevisions;
callback(); callback();
}, },
(callback) => {
// Save the source pad // Save the source pad
db.db.set(`pad:${newPadId}`, newPad, (err) => { (callback) => db.db.set(`pad:${newPadId}`, newPad, callback),
(callback) => {
console.log(`Created: Source Pad: pad:${newPadId}`); console.log(`Created: Source Pad: pad:${newPadId}`);
util.callbackify(newPad.saveToDatabase.bind(newPad))(callback); util.callbackify(newPad.saveToDatabase.bind(newPad))(callback);
});
}, },
], (err) => { ], (err) => {
if (err) throw err; if (err) throw err;