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

stop will not stop immediately. it will stop after the next event #47

Closed
shuhaowu opened this issue Jun 22, 2015 · 3 comments · Fixed by #79
Closed

stop will not stop immediately. it will stop after the next event #47

shuhaowu opened this issue Jun 22, 2015 · 3 comments · Fixed by #79

Comments

@shuhaowu
Copy link

If you have no events coming in, then calling stop after calling run in a separate thread will not cause run to unblock. Instead, it will only stop after another event has been processed.

@shuhaowu
Copy link
Author

Perhaps with an option the run loop could be using IO.select, or something like that.

@e2
Copy link
Contributor

e2 commented May 2, 2016

For completeness, here's a failing example on JRuby:

require 'rb-inotify'

Thread.new do
  INotify::Notifier.new.tap do |notifier|
    Thread.current[:notifier] = notifier
    notifier.watch("/tmp", :modify) { |changes| puts changes.inspect }
    notifier.run
  end
end.run

sleep 3

th[:notifier].close
th.join
 # Never gets here - stuck unless an inotify event occurs

Any workaround possible? Any way to reliably trigger or simulate an inotify event?

@ioquatix
Copy link
Member

I think that right now, this behaviour is outside the scope of the current implementation. The correct solution, is for notifier.run to call select with a wakeup pipe, and for stop to send a single byte down that pipe. I think this belongs elsewhere, e.g. https://github.com/socketry/async/blob/04b3fdae3fa41300777d197b09db54f7ac1d7e2d/lib/async/reactor.rb#L122

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 a pull request may close this issue.

3 participants