Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. require 'eventmachine'
  2.  
  3. class NFuture
  4. include EM::Deferrable
  5. def initialize(times, &block)
  6. @times = times
  7. self.callback(&block)
  8. end
  9.  
  10. def one_more_time(*arg)
  11. @times -= 1
  12. self.succeed(*arg) if @times == 0
  13. end
  14. end
  15.  
  16. n = NFuture.new 5 do
  17. print "beuha"
  18. EM.stop
  19. end
  20.  
  21. EM.run do
  22. (1..5).each do |i|
  23. EM.add_timer(Random.rand(0.1)) do
  24. puts i
  25. n.one_more_time
  26. end
  27. end
  28. end
Add Comment
Please, Sign In to add comment