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

Events that don't poll #7

Open
purpleidea opened this issue Dec 29, 2018 · 1 comment
Open

Events that don't poll #7

purpleidea opened this issue Dec 29, 2018 · 1 comment

Comments

@purpleidea
Copy link

Hi,

I'm having a look at this lib for possible use in https://github.com/purpleidea/mgmt/ and I noticed:

// Poll the file descriptor

  1. Either this spins constantly (busy loop polling) which is unfortunate since I'd like an event based lib or
  2. Then if it blocks in unix.EpollWait, then there's a bug because we can't unblock on that with ctx closes, we'd have to wait until it returns.

Either way figured I'd mention it in case you had some thoughts.

Lastly, it's generally uncommon or discouraged to expose a channel as part of the public API. It's more common to return a function that blocks, with a cancel() function to unblock it when you want to close and there isn't an event.

HTH, and thanks for the lib!

PS: Is this still being maintained or actively used anywhere?

@realh
Copy link

realh commented Mar 29, 2021

It's a bit late, but the way I usually solve this sort of problem is to have a short timeout in the poll. Something in the order of 0.1s should be short enough not to cause a problematical delay when cancelling, but long enough to have negligible impact on system load.

A better solution would probably be to create a pipe. The receiving end could be added to the poll, and another goroutine could send a byte down the other end when the context gets cancelled. It's a pity go's epoll bindings don't support that.

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