lib/textbringer/utils.rb in textbringer-0.2.4 vs lib/textbringer/utils.rb in textbringer-0.2.5

- old
+ new

@@ -59,11 +59,29 @@ end end end end - def next_tick(*args, &block) - Controller.current.next_tick(*args, &block) + def next_tick(&block) + Controller.current.next_tick(&block) + end + + def next_tick! + q = Queue.new + next_tick do + begin + result = yield + q.push([:ok, result]) + rescue Exception => e + q.push([:error, e]) + end + end + status, value = q.pop + if status == :error + raise value + else + value + end end def read_event Controller.current.read_event end