Class: ZK::Subscription::Base

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/zk/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger, wrapped_logger, wrapped_logger=

Constructor Details

#initialize(parent, block) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)

19
20
21
22
23
24
25
# File 'lib/zk/subscription.rb', line 19

def initialize(parent, block)
  raise ArgumentError, "block must repsond_to?(:call)" unless block.respond_to?(:call)
  raise ArgumentError, "parent must respond_to?(:unregister)" unless parent.respond_to?(:unregister)
  @parent   = parent
  @callable = block
  @mutex    = Monitor.new
end

Instance Attribute Details

#callableObject (readonly)

the user-supplied callback block, used to create a ThreadedCallback


17
18
19
# File 'lib/zk/subscription.rb', line 17

def callable
  @callable
end

#parentObject (readonly)

the object from which we will attempt to #unregister on XXX: need a better name for this


14
15
16
# File 'lib/zk/subscription.rb', line 14

def parent
  @parent
end

Instance Method Details

#unregisterObject

calls unregister on parent, then sets parent to nil


32
33
34
35
36
37
38
39
40
41
# File 'lib/zk/subscription.rb', line 32

def unregister
  obj = nil

  synchronize do
    return false unless @parent
    obj, @parent = @parent, nil
  end

  obj.unregister(self)
end

#unregistered?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/zk/subscription.rb', line 27

def unregistered?
  @parent.nil?
end

#unsubscribeObject

an alias for unregister


44
45
46
# File 'lib/zk/subscription.rb', line 44

def unsubscribe
  unregister
end