@@ -18,18 +18,18 @@ def self.local_endpoint(path = "bus.ipc")
1818 end
1919
2020 class Connection
21- def self . client ( peer )
22- self . new ( peer , 1 )
21+ def self . client ( peer , ** options )
22+ self . new ( peer , 1 , ** options )
2323 end
2424
25- def self . server ( peer )
26- self . new ( peer , 2 )
25+ def self . server ( peer , ** options )
26+ self . new ( peer , 2 , ** options )
2727 end
2828
29- def initialize ( peer , id )
29+ def initialize ( peer , id , wrapper : Wrapper )
3030 @peer = peer
3131
32- @wrapper = Wrapper . new ( self )
32+ @wrapper = wrapper . new ( self )
3333 @unpacker = @wrapper . unpacker ( peer )
3434 @packer = @wrapper . packer ( peer )
3535
@@ -72,23 +72,35 @@ def next_id
7272
7373 # Bind a local object to a name, such that it could be accessed remotely.
7474 #
75- # @returns [String] The (unique) name of the object.
75+ # @returns [Proxy] A proxy instance for the bound object.
76+ def bind ( name , object )
77+ @objects [ name ] = object
78+ return self [ name ]
79+ end
80+
81+ # Generate a proxy name for an object and bind it.
82+ #
83+ # @returns [Proxy] A proxy instance for the bound object.
7684 def proxy ( object )
7785 name = "<#{ object . class } @#{ next_id . to_s ( 16 ) } >" . freeze
7886
87+ return bind ( name , object )
88+ end
89+
90+ # Generate a proxy name for an object and bind it, returning just the name.
91+ # Used for serialization when you need the name string, not a Proxy instance.
92+ #
93+ # @returns [String] The name of the bound object.
94+ def proxy_name ( object )
95+ name = "<#{ object . class } @#{ next_id . to_s ( 16 ) } >" . freeze
7996 bind ( name , object )
80-
8197 return name
8298 end
8399
84100 def object ( name )
85101 @objects [ name ]
86102 end
87103
88- def bind ( name , object )
89- @objects [ name ] = object
90- end
91-
92104 private def finalize ( name )
93105 proc { @finalized << name }
94106 end
@@ -102,7 +114,7 @@ def [](name)
102114 proxy = Proxy . new ( self , name )
103115 @proxies [ name ] = proxy
104116
105- ObjectSpace . define_finalizer ( proxy , finalize ( name ) )
117+ :: ObjectSpace . define_finalizer ( proxy , finalize ( name ) )
106118 end
107119
108120 return proxy
@@ -150,7 +162,7 @@ def run
150162 end
151163 else
152164 transaction = @transactions [ message . id ]
153- transaction . received . enqueue ( message )
165+ transaction . received . push ( message )
154166 end
155167 end
156168 ensure
0 commit comments