Sha256: 697c6add6d33192ee5543466e3cc40ef3a23129d290765f10ea0375ba48626ae

Contents?: true

Size: 688 Bytes

Versions: 2

Compression:

Stored size: 688 Bytes

Contents

module GraphQL::Batch
  class Executor
    THREAD_KEY = :"#{name}.batched_queries"
    private_constant :THREAD_KEY

    def self.current
      Thread.current[THREAD_KEY] ||= new
    end

    attr_reader :loaders

    def initialize
      @loaders = {}
    end

    def shift
      @loaders.shift.last
    end

    def tick
      shift.resolve
    end

    def wait(promise)
      tick while promise.pending? && !loaders.empty?
      if promise.pending?
        promise.reject(BrokenPromiseError.new("Promise wasn't fulfilled after all queries were loaded"))
      end
    end

    def wait_all
      tick until loaders.empty?
    end

    def clear
      loaders.clear
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-batch-0.2.2 lib/graphql/batch/executor.rb
graphql-batch-0.2.1 lib/graphql/batch/executor.rb