// generate array of 1000 random callbacks, half of which are async
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
var arr = [];
for (var i=0; i<1000; i++) {
if(Math.random() < 0.5){
arr.push(new Function("a", "return a+1"))
} else {
arr.push(new AsyncFunction("a", "return a+1"))
}
}
(async function(){
var x = 0;
for(const f of arr){
let r = await f(x);
x = r;
}
})().then(function(){deferred.resolve()})
(async function(){
var x = 0;
for(const f of arr){
let r = f(x);
if (typeof r?.then === 'function') {
r = await r
}
x = r
}
})().then(function(){deferred.resolve()})