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 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