Skip to content

Instantly share code, notes, and snippets.

@dasch
Created December 7, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasch/30ceb6dc8146dfdad430e056f8d1f45a to your computer and use it in GitHub Desktop.
Save dasch/30ceb6dc8146dfdad430e056f8d1f45a to your computer and use it in GitHub Desktop.
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