Created
December 7, 2016 13:46
-
-
Save dasch/30ceb6dc8146dfdad430e056f8d1f45a 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
class IoFuture | |
def initialize(io, &block) | |
@io, @block = io, block | |
end | |
def to_io | |
@io | |
end | |
def value | |
@value ||= block.call | |
end | |
end | |
future1 = IoFuture.new(socket1) { socket1.gets } | |
future2 = IoFuture.new(socket2) { socket2.gets } | |
IO.select([future1, future2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment