Class: BubbleWrap::Reactor::ThreadAwareDeferrable

Inherits:
DefaultDeferrable show all
Includes:
Deferrable
Defined in:
motion/reactor/thread_aware_deferrable.rb

Instance Method Summary collapse

Methods included from Deferrable

#callback_delegate, #cancel_timeout, #delegate, #errback_delegate, #fail, #set_deferred_status, #succeed, #timeout

Instance Method Details

#cache_block_queue(&blk) ⇒ Object


29
30
31
32
33
# File 'motion/reactor/thread_aware_deferrable.rb', line 29

def cache_block_queue(&blk)
  return unless blk
  @queue_cache ||= {}
  @queue_cache[blk.object_id] = Dispatch::Queue.current
end

#callback(&blk) ⇒ Object

need to store the the queue in callback / errback


8
9
10
11
12
# File 'motion/reactor/thread_aware_deferrable.rb', line 8

def callback(&blk)
  return unless blk
  cache_block_queue(&blk)
  super(&blk)
end

#errback(&blk) ⇒ Object


14
15
16
17
18
# File 'motion/reactor/thread_aware_deferrable.rb', line 14

def errback(&blk)
  return unless blk
  cache_block_queue(&blk)
  super(&blk)
end

#execute_block(&blk) ⇒ Object


20
21
22
23
24
25
26
27
# File 'motion/reactor/thread_aware_deferrable.rb', line 20

def execute_block(&blk)
  return unless blk
  queue = @queue_cache.delete(blk.object_id)
  return unless queue
  queue.async do
    blk.call(*@deferred_args)
  end
end