Skip to content

Instantly share code, notes, and snippets.

@headius
Forked from ahoward/kew.rb
Last active December 16, 2015 14:29
Show Gist options
  • Save headius/5449567 to your computer and use it in GitHub Desktop.
Save headius/5449567 to your computer and use it in GitHub Desktop.
class Kew
require 'socket'
def initialize
@in, @out = IO.pipe
end
def push(object)
buf = Marshal.dump(object)
@out.puts(buf.size)
@out.write(buf)
end
def pop
size = @in.gets.to_i
buf = @in.read(size)
Marshal.load(buf)
end
end
k = Kew.new
Thread.new do
loop do
p k.pop.last
end
end
3.times do
k.push [0,1,2, 42]
end
sleep
__END__
42
42
42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment