Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User input is blocked #4

Open
Sundin opened this issue Jul 21, 2017 · 1 comment
Open

User input is blocked #4

Sundin opened this issue Jul 21, 2017 · 1 comment

Comments

@Sundin
Copy link

Sundin commented Jul 21, 2017

Hi! Thanks for this library and the wonderful blog post.

I have wrapped my data loading using next-frame, something like this:

async loadData() { 
    ...get contentArray from database...

    await Promise.all(contentArray.map(async (item) => { 
            await nextFrame(); 
            ...do some stuff with item...
    }));

    ...do some more stuff...
}

It sure prevented the GUI rendering from being blocked while the data loads, but for some reason the GUI doesn't respond to any input (pressing buttons etc) until the loadData method has finished. Do I do something wrong or is this just the way it is?

Update:
Just out of curiosity, I put like ten await nextFrame(); in there, and then the GUI got more responsive, even if the data loading obviously took a lot longer to finish.

@rcorrie
Copy link

rcorrie commented Apr 2, 2018

I know this is close to a year late, but hopefully it helps someone else.

Try using basic for loops instead of the map method, to map your data.

async loadData() { 
    ...get contentArray from database...

    let promises = [];

    for(let i = 0; i < contentArray.length; i++) {
        await nextFrame();
        let item = contentArray[i];
        let newItem = ...do some stuff with item...
        promises.push(newItem);
    }

    await Promise.all(promises);

    ...do some more stuff...
}

The map method incurs some unneeded overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants