mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: awaitable websockets (#7645)
* feat: awaitable websockets Adding in conditionals to check the method to call, and handling it as a promise vs. a regular function depending on whether the method itself is an asynchronous function. * fix: switch to .then-checking for awaitable check * fix: proper use of .then check
This commit is contained in:
@@ -131,6 +131,7 @@ function onMessage(socket, payload) {
|
||||
return socket.disconnect();
|
||||
}
|
||||
|
||||
var cbCalled = false;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
checkMaintenance(socket, next);
|
||||
@@ -146,9 +147,19 @@ function onMessage(socket, payload) {
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
methodToCall(socket, params, next);
|
||||
const returned = methodToCall(socket, params, next);
|
||||
if (returned && typeof returned.then === 'function') {
|
||||
returned.then((payload) => {
|
||||
next(null, payload);
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
], function (err, result) {
|
||||
if (cbCalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
cbCalled = true;
|
||||
callback(err ? { message: err.message } : null, result);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user