Last active
February 21, 2019 19:30
Revisions
-
brain64bit revised this gist
Feb 21, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,9 @@ writer = IO.new(fd) writer.sync = true i = 1 while true do writer.puts "#{i} - #{SecureRandom.uuid}" sleep 1 i += 1 end writer.close ``` -
brain64bit created this gist
Feb 21, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ ### Writing a file using IO producer will write a single line of string to file every 1s ```ruby require 'securerandom' fd = IO.sysopen("/tmp/lala.log", "w+") writer = IO.new(fd) writer.sync = true i = 1 while true do writer.puts "#{i} - #{SecureRandom.uuid}" sleep 1 i += 1 end writer.close ``` ### Slurping a file using IO subscriber will read a file every 3s ```ruby fd = IO.sysopen("/tmp/lala.log") reader = IO.new(fd) while (row = reader.gets) != nil do data = row.chomp puts ">>> #{data}" if reader.eof? puts "--------" sleep 3 end end reader.close ```