Method: LightIO::Core::IOloop#wait
- Defined in:
- lib/lightio/core/ioloop.rb
#wait(watcher) ⇒ Object
Wait a watcher, watcher can be a timer or socket. see LightIO::Watchers module for detail
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lightio/core/ioloop.rb', line 37 def wait(watcher) future = Future.new # add watcher to loop id = Object.new watcher.set_callback {future.transfer id} watcher.start(self) # trigger a fiber switch # wait until watcher is ok # then do work if (result = future.value) != id raise InvalidTransferError, "expect #{id}, but get #{result}" end end |