const delayedResponses = {
delays: [500, 1300, 3500],
wait(delay) {
return new Promise((resolve) => {
setTimeout(resolve, delay);
});
},
async *[Symbol.asyncIterator]() {
for (const delay of this.delays) {
await this.wait(delay);
yield `Delayed response for ${delay} milliseconds`;
}
},
};
(async () => {
for await (const response of delayedResponses) {
console.log(response);
}
})();
// Expected output: "Delayed response for 500 milliseconds"
// Expected output: "Delayed response for 1300 milliseconds"
// Expected output: "Delayed response for 3500 milliseconds"