1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
# frozen_string_literal: true
# wat.rb
require 'async'
require_relative '../../lib/async/io'
require 'digest/sha1'
require 'securerandom'
Async.run do |task|
r, w = IO.pipe.map { |io| Async::IO.try_convert(io) }
task.async do |subtask|
s = Digest::SHA1.new
l = 0
100.times do
bytes = SecureRandom.bytes(4000)
s << bytes
w << bytes
l += bytes.bytesize
end
w.close
p [:write, l, s.hexdigest]
end
task.async do |subtask|
s = Digest::SHA1.new
l = 0
while b = r.read(4096)
s << b
l += b.bytesize
end
p [:read, l, s.hexdigest]
end
end
|