@@ -67,12 +67,11 @@ def prime(key, value)
67
67
cache [ cache_key ( key ) ] ||= ::Promise . resolve ( value ) . tap { |p | p . source = self }
68
68
end
69
69
70
- def on_any_wait
71
- return if resolved?
72
- load_keys = queue # "Peek" the queue, but don't consume it.
73
- # TODO: Should we have a "peek queue" / "async queue", that we can consume here, to prevent
74
- # duplicate calls to perform_on_wait? (perform_on_wait should be idempotent anyway, but...)
75
- perform_on_wait ( load_keys )
70
+ # Called when any GraphQL::Batch::Loader starts waiting. May be called more than once per loader, if
71
+ # the loader is waiting multiple times. Will not be called once per promise.
72
+ #
73
+ # Use GraphQL::Batch::Async for the common way to use this.
74
+ def on_any_loader_wait
76
75
end
77
76
78
77
def resolve # :nodoc:
@@ -136,36 +135,6 @@ def fulfilled?(key)
136
135
promise . pending? && promise . source != self
137
136
end
138
137
139
- def perform_on_wait ( keys )
140
- # FIXME: Better name?
141
- # Interface to add custom code to e.g. trigger async operations when any loader starts waiting.
142
- # Example:
143
- #
144
- # def initialize
145
- # super()
146
- # @futures = {}
147
- # end
148
- #
149
- # def perform_on_wait(keys)
150
- # keys.each do |key|
151
- # future(key)
152
- # end
153
- # end
154
- #
155
- # def perform(keys)
156
- # defer # let other non-async loaders run to completion first.
157
- # keys.each do |key|
158
- # future(key).value!
159
- # end
160
- # end
161
- #
162
- # def future(key)
163
- # @futures[key] ||= Concurrent::Promises.future do
164
- # # Perform the async operation
165
- # end
166
- # end
167
- end
168
-
169
138
# Must override to load the keys and call #fulfill for each key
170
139
def perform ( keys )
171
140
raise NotImplementedError
@@ -188,7 +157,7 @@ def finish_resolve(key)
188
157
189
158
def defer
190
159
@deferred = true
191
- executor . defer ( self )
160
+ executor . defer_to_other_loaders
192
161
ensure
193
162
@deferred = false
194
163
end
0 commit comments