Class: Yrpc::Interceptors::Registry
- Inherits:
-
Object
- Object
- Yrpc::Interceptors::Registry
- Defined in:
- lib/yrpc/interceptors/register.rb
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#interceptors_mutex(&block) ⇒ Object
ruby 互斥锁,防止线程对资源进行竞争,导致资源不同步.
- #use(interceptor_class, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
5 6 7 |
# File 'lib/yrpc/interceptors/register.rb', line 5 def initialize @interceptors ||= [] end |
Instance Method Details
#interceptors_mutex(&block) ⇒ Object
ruby 互斥锁,防止线程对资源进行竞争,导致资源不同步
19 20 21 22 23 24 25 |
# File 'lib/yrpc/interceptors/register.rb', line 19 def interceptors_mutex(&block) @interceptors_mutex ||= begin require 'monitor' Monitor.new end @interceptors_mutex.synchronize(&block) end |
#use(interceptor_class, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/yrpc/interceptors/register.rb', line 9 def use(interceptor_class, = {}) interceptors_mutex do @interceptors << { klass: interceptor_class, options: } end end |