1
by Pirate Praveen
Import upstream version 1.2.1 |
1 |
# frozen_string_literal: true
|
2 |
||
3 |
class BatchLoader |
|
4 |
class Executor |
|
5 |
NAMESPACE = :batch_loader |
|
6 |
||
7 |
def self.ensure_current |
|
8 |
Thread.current[NAMESPACE] ||= new |
|
9 |
end
|
|
10 |
||
11 |
def self.current |
|
12 |
Thread.current[NAMESPACE] |
|
13 |
end
|
|
14 |
||
15 |
def self.clear_current |
|
16 |
Thread.current[NAMESPACE] = nil |
|
17 |
end
|
|
18 |
||
19 |
attr_reader :items_by_block, :loaded_values_by_block |
|
20 |
||
21 |
def initialize |
|
22 |
@items_by_block = Hash.new { |hash, key| hash[key] = Set.new } |
|
23 |
@loaded_values_by_block = Hash.new { |hash, key| hash[key] = {} } |
|
24 |
end
|
|
25 |
end
|
|
26 |
end
|