Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'eventmachine'
- class NFuture
- include EM::Deferrable
- def initialize(times, &block)
- @times = times
- self.callback(&block)
- end
- def one_more_time(*arg)
- @times -= 1
- self.succeed(*arg) if @times == 0
- end
- end
- n = NFuture.new 5 do
- print "beuha"
- EM.stop
- end
- EM.run do
- (1..5).each do |i|
- EM.add_timer(Random.rand(0.1)) do
- puts i
- n.one_more_time
- end
- end
- end
Add Comment
Please, Sign In to add comment