Polyfill Promise.any for Node v14

Oops, Promise.any was added in Node 15, but prod uses Node 14! Polyfill it!
This commit is contained in:
Emi Matchu 2021-08-17 01:43:39 -07:00
parent a1243ad08f
commit c28366772d

View file

@ -145,6 +145,20 @@ function reject(res, message, status = 400) {
return res.status(status).send(message); return res.status(status).send(message);
} }
// Polyfill Promise.any for older Node: https://github.com/ungap/promise-any
Promise.any =
Promise.any ||
function ($) {
return new Promise(function (D, E, A, L) {
A = [];
L = $.map(function ($, i) {
return Promise.resolve($).then(D, function (O) {
return ((A[i] = O), --L) || E({ errors: A });
});
}).length;
});
};
async function handleWithBeeline(req, res) { async function handleWithBeeline(req, res) {
beeline.withTrace( beeline.withTrace(
{ name: "api/assetImage", operation_name: "api/assetImage" }, { name: "api/assetImage", operation_name: "api/assetImage" },