-
-
Save vpereira/a4cb824199efdce1af973ee75e9627aa 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
require "http/client" | |
def do_stuff(ch : Channel) | |
2.times do |i| | |
spawn do | |
r = HTTP::Client.get "http://www.bbc.com" | |
ch.send "#{i}>" + r.body[0..10] | |
end | |
Fiber.yield | |
end | |
end | |
ch = Channel(String).new | |
do_stuff(ch) | |
spawn do | |
while d = ch.receive? | |
puts d | |
end | |
end | |
sleep 0.5 | |
ch.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment