Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Last active June 8, 2018 08:04
Show Gist options
  • Save dminuoso/06fd82538491d1ab7fa944f52145b395 to your computer and use it in GitHub Desktop.
Save dminuoso/06fd82538491d1ab7fa944f52145b395 to your computer and use it in GitHub Desktop.
def on_request
key = nil
Concurrent.atomically do
key = RsaBox.take
end
...
end
RsaBox = Concurrent::MVar.new
producer = Thread.new do
loop do
key = expensive_computation
Concurrent.atomically do
RsaBox.put key
end
end
end
...
producer.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment