Sha256: 93d8bc0eebae181c2e92d4e3b6846aad052adf4e510a067be9abd5c3bbc9c6f8
Contents?: true
Size: 622 Bytes
Versions: 3
Compression:
Stored size: 622 Bytes
Contents
# frozen_string_literal: true require 'json' class Channel def initialize @in, @out = IO.pipe end def after_fork @out.close end def receive if data = @in.gets JSON.parse(data, symbolize_names: true) end end def send(**message) data = JSON.dump(message) @out.puts(data) end end status = Channel.new pid = fork do status.send(ready: false, status: "Initializing...") # exit(-1) # crash status.send(ready: true, status: "Initialization Complete!") end status.after_fork while message = status.receive pp message end pid, status = Process.waitpid2(pid) puts "Status: #{status}"
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
async-container-0.16.5 | examples/channel.rb |
async-container-0.16.4 | examples/channel.rb |
async-container-0.16.3 | examples/channel.rb |