Skip to content

src: add complement APIs for event loop integration#3299

Closed
zcbenz wants to merge 1 commit into
libuv:masterfrom
zcbenz:new-timer-callback
Closed

src: add complement APIs for event loop integration#3299
zcbenz wants to merge 1 commit into
libuv:masterfrom
zcbenz:new-timer-callback

Conversation

@zcbenz

@zcbenz zcbenz commented Sep 7, 2021

Copy link
Copy Markdown
Contributor

When integrating an uv event loop with other event loops, we usually listen to events on the backend fd of the uv event loop. However in libuv timers do not trigger events on the backend fd, and this would cause problem like, Node's setTimeout not working in Electron. (See also #1565, #1651.)

To solve this, we need to get notified whenever a timer is started, and then update the timeout when listening to backend fd. This PR adds the uv_loop_set_timer_started_callback API for this purpose.

This PR is different from the current approach used in Electron (#1921), as the latter sends notifications for some unneeded cases.

I have added a test in test/test-embed.c to demonstrate the problem of timers with event loop integration, and how this API can be used to fix it.

/cc @bnoordhuis

@zcbenz zcbenz force-pushed the new-timer-callback branch from 41b227a to 18a1a9a Compare September 7, 2021 12:32
@zcbenz zcbenz changed the title src: add complement APIs for loop integration src: add complement APIs for event loop integration Sep 7, 2021
@vtjnash

vtjnash commented Sep 8, 2021

Copy link
Copy Markdown
Member

Seems related to #3234 also?

Since libuv is currently fully-synchronous, I don't think this seems the right approach right now.

@zcbenz

zcbenz commented Sep 9, 2021

Copy link
Copy Markdown
Contributor Author

Yeah #3234 is also related, but it can not solve the problem of timers not working in event loop integration: the change of uv_backend_timeout's return value does not interrupt the polling of backend fd, so the polling will still use the old timeout (which is usually -1).

Since libuv is currently fully-synchronous, I don't think this seems the right approach right now.

How do you think about adding a new option to uv loop that, with it changes of watcher queue will implicitly cause an interruption to the polling of backend fd?

uv_loop_configure(loop, UV_INTERRUPT_ON_WATCHER_QUEUE_CHANGE);

In this way we don't need to expose a hook style API.

@zcbenz

zcbenz commented Sep 17, 2021

Copy link
Copy Markdown
Contributor Author

I'm closing this PR in favor of #3308.

@zcbenz zcbenz closed this Sep 17, 2021
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

Successfully merging this pull request may close these issues.

2 participants