Created
October 30, 2021 19:44
-
-
Save lamont-granquist/39409838626b22433f8bf1878276b3c1 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
#!/usr/bin/env ruby | |
require "async" | |
class Global | |
class << self | |
attr_accessor :counter | |
def counter | |
@counter ||= 0 | |
end | |
end | |
end | |
Async do |task| | |
1000.times do | |
task.async do | |
val = Global.counter | |
sleep 0.0001 | |
val += 1 | |
Global.counter = val | |
end | |
end | |
end | |
puts Global.counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment