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