Class: Issuesrc::EventLoop
- Inherits:
-
Object
- Object
- Issuesrc::EventLoop
- Defined in:
- lib/issuesrc/event_loop.rb
Direct Known Subclasses
Instance Method Summary collapse
- #async_http_request(method, url, opts, &callback) ⇒ Object
-
#initialize ⇒ EventLoop
constructor
A new instance of EventLoop.
- #wait_for_pending ⇒ Object
Constructor Details
#initialize ⇒ EventLoop
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/issuesrc/event_loop.rb', line 18 def initialize() @pending = [] @http_channel = EM::Channel.new @waiting = 0 @wakeup_when_done = [] @thread = Thread.new do begin EM.run do handle_http_channel() end rescue # TODO(#24): Proper error handling here. wakeup_waiters() end end end |
Instance Method Details
#async_http_request(method, url, opts, &callback) ⇒ Object
6 7 8 |
# File 'lib/issuesrc/event_loop.rb', line 6 def async_http_request(method, url, opts, &callback) @http_channel.push([method, url, opts, callback]) end |
#wait_for_pending ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/issuesrc/event_loop.rb', line 10 def wait_for_pending() if @waiting == 0 || !@thread.alive? return end @wakeup_when_done << Thread.current Thread.stop end |