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

Window.events blocks all other events #72

Open
chirsz-ever opened this issue Apr 25, 2024 · 3 comments
Open

Window.events blocks all other events #72

chirsz-ever opened this issue Apr 25, 2024 · 3 comments

Comments

@chirsz-ever
Copy link

example code:

import {
    EventType,
    WindowBuilder,
    getKeyName
} from "jsr:@divy/[email protected]";

const win = new WindowBuilder("Three.js demo - webgpu/backdrop", 800, 600).build();

new Promise((resolve) => setTimeout(() => {
    console.log("timeout");
    resolve(undefined);
}, 1000));

for await (const event of win.events()) {
    if (event.type === EventType.Quit) break;
    else if (event.type !== EventType.Draw) continue;

    // FIXME: deno_sdl2 UI events would block network events?
    // await new Promise((resolve) => setTimeout(resolve, 1));
}

"timeout" would not be logged until the window close, or add the commented await line.

@littledivy
Copy link
Owner

win.events() returns a synchronous iterator that blocks the event loop until a new SDL event happens. Platforms like macOS assume GUI thread is the main thread.

There are a few ways to work around this:

@littledivy
Copy link
Owner

littledivy commented Apr 26, 2024

Another workaround is to use win.events(false) which will use SDL_PollEvent instead of WaitEvent and run the background tasks. Downside being that CPU will be busy when there is no work to do

@chirsz-ever
Copy link
Author

I noticed the wait argument. Do you have any idea to make SDL_WaitEvent work with tokio? SDL_WaitEvent would block the thread until get an event. the SDL2 implementation looks like just polling until an event comes.

Maybe just await new Promise((resolve) => queueMicrotask(resolve)); before yeild anything?

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