Skip to content

Instantly share code, notes, and snippets.

@vpereira

vpereira/1.cr Secret

Created December 28, 2017 21:56
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 vpereira/7956983838074df43200b5eea3e03cea to your computer and use it in GitHub Desktop.
Save vpereira/7956983838074df43200b5eea3e03cea to your computer and use it in GitHub Desktop.
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