Anonymous avatar Anonymous committed bcd4867

test_notify

Comments (0)

Files changed (2)

ruby/lib/msgpack/rpc.rb

 	def notify_real(method, param)
 		method = method.to_s unless method.is_a?(Integer)
 		@sock.send_notify method, param
+		nil
 	end
 end
 
 
 	def on_request(method, param, res)
 		begin
-			unless @accept.include?(method)
-				raise NoMethodError, "method `#{method}' is not accepted"
-			end
-			ret = @obj.send(method, *param)
+			result = forward_method(method, param)
 		rescue
 			res.error($!.to_s)
 			return
 		end
-		if ret.is_a?(AsyncResult)
-			ret.responder = res
+		if result.is_a?(AsyncResult)
+			result.responder = res
 		else
-			res.result(ret)
+			res.result(result)
 		end
 	end
 
 	def on_notify(method, param)
-		# FIXME notify support
-		raise RPCError.new("unexpected notify message")
+		forward_method(method, param)
+	rescue
 	end
 
 	def on_response(msgid, error, result)
 		# do nothing
 		@sock = nil
 	end
+
+	private
+	def forward_method(method, param)
+		unless @accept.include?(method)
+			raise NoMethodError, "method `#{method}' is not accepted"
+		end
+		@obj.send(method, *param)
+	end
 end
 
 Loop = ::Rev::Loop

ruby/test/msgpack_rpc_test.rb

 	end
 
 
+	def test_notify
+		svr, cli = start_server
+
+		cli.notify(:hello)
+		cli.notify(:sum, 1, 2)
+	end
+
+
 	def test_hidden
 		svr, cli = start_server
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.