Synchronous concurrency: Difference between revisions

Content added Content deleted
Line 684: Line 684:


<lang ruby>File.write("input.txt", "a\nb\nc")
<lang ruby>File.write("input.txt", "a\nb\nc")

lines = Channel(String).new
lines = Channel(String).new

spawn do
spawn do
File.each_line("input.txt") do |line|
File.each_line("input.txt") do |line|
Line 693: Line 693:
lines.close
lines.close
end
end

while line = lines.receive?
begin
puts line
while
line = lines.receive
puts line
end
rescue ex : Channel::ClosedError
end
end