Index: third_party/grpc/src/ruby/lib/grpc/notifier.rb |
diff --git a/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb b/third_party/grpc/src/ruby/lib/grpc/notifier.rb |
similarity index 68% |
copy from third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb |
copy to third_party/grpc/src/ruby/lib/grpc/notifier.rb |
index e10266ba2f3637d655c2de89c285558c987c613b..caa18bbed6de4f30fa899ba6011e2e9e95d28317 100644 |
--- a/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb |
+++ b/third_party/grpc/src/ruby/lib/grpc/notifier.rb |
@@ -1,6 +1,5 @@ |
-# Protocol Buffers - Google's data interchange format |
-# Copyright 2008 Google Inc. All rights reserved. |
-# https://developers.google.com/protocol-buffers/ |
+# Copyright 2015, Google Inc. |
+# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
@@ -28,26 +27,34 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-module Google |
- module Protobuf |
- module MessageExts |
+# GRPC contains the General RPC module. |
+module GRPC |
+ # Notifier is useful high-level synchronization primitive. |
+ class Notifier |
+ attr_reader :payload, :notified |
+ alias_method :notified?, :notified |
- #this is only called in jruby; mri loades the ClassMethods differently |
- def self.included(klass) |
- klass.extend(ClassMethods) |
- end |
- |
- module ClassMethods |
- end |
+ def initialize |
+ @mutex = Mutex.new |
+ @cvar = ConditionVariable.new |
+ @notified = false |
+ @payload = nil |
+ end |
- def to_json |
- self.class.encode_json(self) |
+ def wait |
+ @mutex.synchronize do |
+ @cvar.wait(@mutex) until notified? |
end |
+ end |
- def to_proto |
- self.class.encode(self) |
+ def notify(payload) |
+ @mutex.synchronize do |
+ return Error.new('already notified') if notified? |
+ @payload = payload |
+ @notified = true |
+ @cvar.signal |
+ return nil |
end |
- |
end |
end |
end |