Class: RMXExecutionBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/motion/RMXExecutionBlock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deadObject

Returns the value of attribute dead.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def dead
  @dead
end

#descObject

Returns the value of attribute desc.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def desc
  @desc
end

#limitObject

Returns the value of attribute limit.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def limit
  @limit
end

#metaObject

Returns the value of attribute meta.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def meta
  @meta
end

#queueObject

Returns the value of attribute queue.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def queue
  @queue
end

#strongObject

Returns the value of attribute strong.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def strong
  @strong
end

#the_blockObject

Returns the value of attribute the_block.



2
3
4
# File 'lib/motion/RMXExecutionBlock.rb', line 2

def the_block
  @the_block
end

Instance Method Details

#actual_queueObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/motion/RMXExecutionBlock.rb', line 10

def actual_queue
  q = queue
  if q == :async
    q = RMXEventsFromProxy::QUEUE
  elsif q == :main
    q = Dispatch::Queue.main
  end
  q ||= Dispatch::Queue.main
  q
end

#block=(_block) ⇒ Object



5
6
7
8
# File 'lib/motion/RMXExecutionBlock.rb', line 5

def block=(_block)
  self.block_owner = _block.owner
  self.the_block = RMX.safe_block(_block)
end

#call(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/motion/RMXExecutionBlock.rb', line 21

def call(*args)
  should_cleanup = false
  if !dead && (blk = the_block) && (o = block_owner) && (q = actual_queue)
    q.async do
      blk.call(*args)
      blk
      o
    end
  else
    should_cleanup = true
  end
  if limit
    if limit > 0
      self.limit -= 1
    end
    if limit == 0
      should_cleanup = true
    end
  end
  if should_cleanup
    self.dead = true
    self.strong = nil
    self.meta = nil
    self.limit = nil
    self.the_block = nil
    self.block_owner = nil
  end
end