Class: Async::Bus::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil) ⇒ Server

Returns a new instance of Server.



29
30
31
32
33
34
# File 'lib/async/bus/server.rb', line 29

def initialize(endpoint = nil)
	@endpoint = endpoint || Protocol.local_endpoint
	@connected = {}
	
	@context = {}
end

Instance Attribute Details

#connectedObject (readonly)

Returns the value of attribute connected.



36
37
38
# File 'lib/async/bus/server.rb', line 36

def connected
  @connected
end

Instance Method Details

#acceptObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/async/bus/server.rb', line 38

def accept
	@endpoint.accept do |peer|
		connection = Protocol::Connection.server(peer)
		@connected[peer] = connection
		
		yield connection
		connection.run
	ensure
		connection = @connected.delete(peer)
		connection&.close
	end
end