var a = [1,2,3];
a[Symbol.asyncIterator] = function() {
return {
i: 0,
next() {
return new Promise((resolve, reject) => {
setTimeout(()=>{
resolve({
value: a[this.i],
done: ++this.i > a.length
});
}, 1000)
});
}
}
}
async function ag(){
try{
for await(var x of a) {
console.log(x);
}
} catch(e) {
console.log(e);
}
}
ag();
(async function ag(){
try{
for await(var x of ['a', 'b', 'c']) {
console.log(x);
}
} catch(e) {
console.log(e);
}
})();