Created
August 7, 2017 19:39
-
-
Save ifyouseewendy/62ad5a4312421940df38e7e19e4bcb6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
rp, wp = IO.pipe | |
mesg = "ping " | |
20.times { |i| | |
print "##{i} " | |
rs, ws, = IO.select([rp], [wp]) | |
require'pry-byebug';binding.pry | |
if r = rs[0] | |
ret = r.read(5) | |
print ret | |
case ret | |
when /ping/ | |
mesg = "pong\n" | |
when /pong/ | |
mesg = "ping " | |
end | |
end | |
if w = ws[0] | |
w.write(mesg) | |
end | |
} | |
# 0 1 ping 2 pong | |
# 3 ping 4 pong | |
# 5 ping 6 pong | |
# 7 ping 8 pong | |
# 9 ping 10 pong | |
# 11 ping 12 pong | |
# 13 ping 14 pong | |
# 15 ping 16 pong | |
# 17 ping 18 pong | |
# 19 ping | |
rp, wp = IO.pipe | |
rs, ws = IO.select([rp], [wp]) | |
# [ | |
# [], | |
# [#<IO:fd 10>], | |
# [] | |
# ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment