Class: Async::Bus::Server

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

Overview

Represents a server that accepts async-bus connections.

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, **options) ⇒ Server

Initialize a new server.



18
19
20
21
# File 'lib/async/bus/server.rb', line 18

def initialize(endpoint = nil, **options)
	@endpoint = endpoint || Protocol.local_endpoint
	@options = options
end

Instance Method Details

#accept(&block) ⇒ Object

Accept incoming connections.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/async/bus/server.rb', line 33

def accept(&block)
	@endpoint.accept do |peer|
		connection = Protocol::Connection.server(peer, **@options)
		
		connected!(connection, &block)
		
		yield connection if block_given?
		
		connection.run
	ensure
		connection&.close
	end
end