Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Last active June 5, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chuckremes/ed78d3c3066194ebf593b163d5631e3e to your computer and use it in GitHub Desktop.
Save chuckremes/ed78d3c3066194ebf593b163d5631e3e to your computer and use it in GitHub Desktop.
# 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