Skip to content

Instantly share code, notes, and snippets.

@takuma-saito
Created May 3, 2020 06:12
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 takuma-saito/2e5fef2a1f0d1488775af5bbb856b244 to your computer and use it in GitHub Desktop.
Save takuma-saito/2e5fef2a1f0d1488775af5bbb856b244 to your computer and use it in GitHub Desktop.
future.rb
class Future
def initialize(&block)
@que = Queue.new
@t = Thread.new {
@que << block.call
}
end
def value
return @que.pop
ensure
@que.close
@t.join
end
end
future = Future.new do
sleep 3.0
'done'
end
p 'ok'
sleep 2.0
p future.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment