Sha256: 1f89a57f704ca2f6891c9bb9a4b3c9399255d34556908b97cae8b9e7062a06f5

Contents?: true

Size: 629 Bytes

Versions: 2

Compression:

Stored size: 629 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
			return 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

2 entries across 2 versions & 1 rubygems

Version Path
async-container-0.16.2 examples/channel.rb
async-container-0.16.1 examples/channel.rb