Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test close channel. #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/myip.cr
Expand Up @@ -3,6 +3,8 @@ require "./myip/*"
require "option_parser"

chan = Channel(Tuple(String, String)).new
terminate = Channel(Nil).new
done = Channel(Nil).new

def get_ip_from_ip138(chan)
spawn do
Expand Down Expand Up @@ -84,15 +86,35 @@ USAGE

size = output_i138 ? iframe_size + 1 : iframe_size

size.times do |i|
select
when value = chan.receive
title, ip = value

STDERR.puts "#{title}#{ip}"
when timeout 5.seconds
STDERR.puts "Timeout!"
exit
spawn do
loop do
select
when value = chan.receive
title, ip = value

STDERR.puts "#{title}#{ip}"
when terminate.receive?
break
when timeout 5.seconds
STDERR.puts "Timeout!"
exit
end
end
done.close
end

terminate.close
done.receive?

# size.times do |i|
# select
# when value = chan.receive
# title, ip = value

# STDERR.puts "#{title}#{ip}"
# when timeout 5.seconds
# STDERR.puts "Timeout!"
# exit
# end
# end
end