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
v1.18.x
Julian Lam 6 years ago committed by GitHub
parent a6436716ea
commit aee47b299a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,6 +131,7 @@ function onMessage(socket, payload) {
return socket.disconnect(); return socket.disconnect();
} }
var cbCalled = false;
async.waterfall([ async.waterfall([
function (next) { function (next) {
checkMaintenance(socket, next); checkMaintenance(socket, next);
@ -146,9 +147,19 @@ function onMessage(socket, payload) {
} }
}, },
function (next) { 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) { ], function (err, result) {
if (cbCalled) {
return;
}
cbCalled = true;
callback(err ? { message: err.message } : null, result); callback(err ? { message: err.message } : null, result);
}); });
} }

Loading…
Cancel
Save