Suppose I have some asnyc iterable objects like this:
// Promisified sleep function
const sleep = ms => new Promise((resolve, reject) => {
setTimeout(() => resolve(ms), ms);
});
const a = {
[Symbol.asyncIterator]: async function * () {
yield 'a';
await sleep(1000);
yield 'b';
await sleep(2000);
yield 'c';
},
};
const b = {
[Symbol.asyncIterator]: async function * () {
await sleep(6000);
yield 'i';
yield 'j';
await sleep(2000);
yield 'k';
},
};
const c = {
[Symbol.asyncIterator]: async function * () {
yield 'x';
await sleep(2000);
yield 'y';
await sleep(8000);
yield 'z';
await sleep(10000);
throw new Error('You have gone too far! ');
},
};
Now, suppose I can concat them like this:
const abcs = async function * () {
yield * a;
yield * b;
yield * c;
};
The (first 9) items yielded will be:
(async () => {
const limit = 9;
let i = 0;
const xs = [];
for await (const x of abcs()) {
xs.push(x);
i++;
if (i === limit) {
break;
}
}
console.log(xs);
})().catch(error => console.error(error));
// [ 'a', 'b', 'c', 'i', 'j', 'k', 'x', 'y', 'z' ]
But imagine that I do not care about the order, that a
, b
and c
yield at different speeds, and that I want to yield as quickly as possible.
How can I rewrite this loop so that x
s are yielded as soon as possible, ignoring order?
It is also possible that a
, b
or c
are infinite sequences, so the solution must not require all elements to be buffered into an array.
lasix – can i buy furosemide over the counter lasix 620 mg
best price for generic viagra – how to buy viagra over the counter uk viagra tablet
buy tadalafil 20mg price canada – how to get cialis over the counter cialis online 20mg
ivermectin virus – ivermectin human stromectol order online
slot machine games – doubleu casino wind creek casino online play
top rated ed pills – dr phil and steve harvey ed pill erectile dysfunction drugs over the counter
prices for 5mg prednisone – generic prednisone prednisone dosage
best viagra uk – sildenafil purchase canada buy generic sildenafil uk
prices cialis – Cialis next day delivery generic cialis 60 mg india
stromectol without prescription – stromectol price uk stromectol medicine
roman ed pills – ed pills comparison what is the latest treatment for erectile dysfunction
buy cheap neurontin – neurontin 4000 mg synthroid 125 mcg tablet cost
ivermectin 3mg price – stromectol order online stromectol canada
side effects of vardenafil – generic vardenafil online cheap ed pills
ivermectin 0.1 – buy stromectol for humans australia ivermectin dose for covid
918132 28638Blogs ou really should be reading […]Here is a superb Blog You might Discover Fascinating that we Encourage You[…] 551040
305564 375946You produced some decent points there. I looked on the internet for that dilemma and located a lot of people will go in addition to with the web web site. 938923
can you buy prednisone over the counter in mexico – sterapred prednisone cream brand name
buy sildalis online cheap – finasteride 1mg generic buy glucophage 1000mg without prescription
cost hydroxychloroquine – purchase plaquenil pills hydroxychloroquine 200mg without prescription
buy viagra 50mg for sale – purchase cialis for sale cialis daily cost
viagra pas cher – vrai viagra 200mg prix cialis 20mg pas cher
ivermectin 12 – purchase provigil ivermectin 12mg pills for humans
tadalafil cost walmart tadalafil drug
what is tadalafil https://cialisbusd.com/
purchase pregabalin for sale – azithromycin 500mg over the counter order azithromycin 500mg pill
tadalafil online with out prescription tadalafil blood pressure
buy tadalafil tadalafil dosage
purchase cenforce online – generic allopurinol 100mg order zovirax 400mg sale
order hydroxyzine generic – buy generic crestor 10mg buy crestor online cheap
buy generic cialis online with mastercard where to order tadalafil tablets
buy tadalafil https://cialisusdc.com/
tadalafil brands best price usa tadalafil
where to buy tadalafil on line canada generic tadalafil
tadalafil online with out prescription https://cialiswbtc.com/
tadalafil online with out prescription tadalafil drug
cost tadalafil generic best price usa tadalafil
buy provigil 200mg pills provigil 100mg price