-
-
Save dminuoso/06fd82538491d1ab7fa944f52145b395 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
def on_request | |
key = nil | |
Concurrent.atomically do | |
key = RsaBox.take | |
end | |
... | |
end |
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
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