async generators and Array.from

Why Array.from() function not accepts async generator?

async function* word() {
   yield 'I';
   yield 'have';
   yield 'a';
   yield 'question';

Promise.all(Array.from(word())).then(words => console.assert('I have a question' === words.join(' ')));

Because Array.from is synchronous and cannot immediately know when the async iterable ends. It cannot even immediately collect the appropriate amount of promises because it's unknown how many that would be.

You're looking for AsyncIterator.prototype.toArray() method from the iterator helpers proposal.

Thank you so much. I looked up the proposal and there are very neat functions.

I just consider that the generator yield promises when it iterate and doesn't care promise statuses on pending, on fullfill or on reject. But it is not goes next yield while actual promise is on pending.

In this case following samples are not same.

function* generate() {
    yield Promise.resolve(1);
    yield Promise.resolve(2);


async function* generate() {
    yield 1;
    yield 2;