Class: IO
- Inherits:
-
Object
- Object
- IO
- Defined in:
- lib/rvideo/command_executor.rb
Instance Method Summary collapse
Instance Method Details
#each_with_timeout(timeout, sep_string = $/) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rvideo/command_executor.rb', line 5 def each_with_timeout(timeout, sep_string=$/) q = Queue.new th = nil timer_set = lambda do |timeout| th = new_thread{ to(timeout){ q.pop } } end timer_cancel = lambda do |timeout| th.kill if th rescue nil end timer_set[timeout] begin self.each(sep_string) do |buf| timer_cancel[timeout] yield buf timer_set[timeout] end ensure timer_cancel[timeout] end end |