Skip to content

Instantly share code, notes, and snippets.

@vpereira

vpereira/p1.cr Secret

Last active December 29, 2017 09:47
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/a4cb824199efdce1af973ee75e9627aa to your computer and use it in GitHub Desktop.
Save vpereira/a4cb824199efdce1af973ee75e9627aa to your computer and use it in GitHub Desktop.
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