Sha256: a41c8bf2801781c08cb396467be739d849777722d92464f99838521aeeb5543d

Contents?: true

Size: 818 Bytes

Versions: 8

Compression:

Stored size: 818 Bytes

Contents

module BubbleWrap
  module Reactor
    class ThreadAwareDeferrable < DefaultDeferrable
      include ::BubbleWrap::Reactor::Deferrable


      # need to store the the queue in callback / errback
      def callback(&blk)
        return unless blk
        cache_block_queue(&blk)
        super(&blk)
      end

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

      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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bubble-wrap-1.9.7 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.6 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.5 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.4 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.3 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.2 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.1 motion/reactor/thread_aware_deferrable.rb
bubble-wrap-1.9.0 motion/reactor/thread_aware_deferrable.rb