Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2017 22:30
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/047bdc12f4f8b5df78fcd2fef8a25241 to your computer and use it in GitHub Desktop.
Save anonymous/047bdc12f4f8b5df78fcd2fef8a25241 to your computer and use it in GitHub Desktop.
def cappedTimes(limit : Int32 , concurrency : Int32, &block : Int32 -> )
counter = 0
channel = Channel(Int32).new(concurrency)
while counter < limit
channel.send(0)
puts "before spawn"
spawn do
puts "inside fiber"
block.call(counter)
end
puts "after spawn"
channel.receive
counter = counter + 1
end
end
cappedTimes(10,2) do |index|
puts index
doc = Crystagiri::HTML.from_url "https://slashdot.org/"
doc.where_tag "title" {|t| puts t}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment