-
-
Save digitalextremist/3ba6b4a1b9852080165c5e6cc1fe697b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Acts like an array and receives futures. Will yield them as | |
# they become ready. | |
class HackedMultiplexer | |
include Celluloid | |
include Enumerable | |
def initialize | |
@not_ready = [] | |
end | |
def push(obj) | |
@not_ready.push(obj) | |
end | |
alias_method :<<, :push | |
def each(&blk) | |
loop do | |
ready = @not_ready.select { |future| future.ready? } | |
@not_ready -= ready | |
ready.each { |future| yield(future) } | |
break if @not_ready.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment