Skip to content

Instantly share code, notes, and snippets.

/cappedsem.cr Secret

Created March 13, 2017 21:50
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 anonymous/933663e12cc6b230c48e3960d2e32274 to your computer and use it in GitHub Desktop.
Save anonymous/933663e12cc6b230c48e3960d2e32274 to your computer and use it in GitHub Desktop.
def cappedTimes(limit : Int32 , concurrency : Int32)
counter = 0
channel = Channel(Int32).new(concurrency)
while counter < concurrency
channel.send(0)
spawn do
yield(counter)
end
channel.receive
counter = counter + 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment