Sha256: f6371e6f989583ab152aa82e01f6e64f3ab6382226b8d9d850633ef9cea06154

Contents?: true

Size: 893 Bytes

Versions: 3

Compression:

Stored size: 893 Bytes

Contents

module EventMachine
  module Ventually
    class Pool
      def initialize
        @store = []
      end

      def should_run?(eventually)
        case @store.first
        when Array
          @store.first.include?(eventually)
        else
          @store.first == eventually
        end
      end

      def in_parallel
        @store.push []
        yield
      end

      def push(e)
        if @store.last.is_a?(Array)
          @store.last.last.run unless @store.last.last.nil?
          @store.last.push(e)
        else
          @store.last.run unless @store.last.nil?
          @store.push(e)
        end
      end

      def complete(e)
        if @store.first.is_a?(Array)
          @store.first.delete(e)
          @store.shift if @store.last.empty?
        else
          @store.delete(e)
        end
      end

      def empty?
        @store.empty?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
em-ventually-0.1.3 lib/em-ventually/pool.rb
em-ventually-0.1.2 lib/em-ventually/pool.rb
em-ventually-0.1.1 lib/em-ventually/pool.rb