Class: Async::Container::Notify::Server::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/notify/server.rb

Overview

A bound context for receiving messages.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Context

Initialize the context with the given path.



102
103
104
105
106
107
# File 'lib/async/container/notify/server.rb', line 102

def initialize(path)
	@path = path
	@bound = Addrinfo.unix(@path, ::Socket::SOCK_DGRAM).bind
	
	@state = {}
end

Instance Method Details

#closeObject

Close the bound context.



110
111
112
113
114
# File 'lib/async/container/notify/server.rb', line 110

def close
	@bound.close
	
	File.unlink(@path)
end

#receiveObject

Receive a message from the bound context.



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/async/container/notify/server.rb', line 119

def receive
	while true
		data, _address, _flags, *_controls = @bound.recvmsg(MAXIMUM_MESSAGE_SIZE)
		
		message = Server.load(data)
		
		if block_given?
			yield message
		else
			return message
		end
	end
end

#wait_until_readyObject

Wait until a “ready” message is received from the child process.



134
135
136
137
138
139
140
# File 'lib/async/container/notify/server.rb', line 134

def wait_until_ready
	while message = receive
		if message[:ready] == true
			return
		end
	end
end