Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2017 22:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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