@@ -136,26 +136,24 @@ def run
136
136
# This is where an evented approach would be even better -- can we tell which
137
137
# fibers are ready to continue, and continue execution there?
138
138
#
139
- source_fiber_stack = if ( first_source_fiber = create_source_fiber )
139
+ source_fiber_queue = if ( first_source_fiber = create_source_fiber )
140
140
[ first_source_fiber ]
141
141
else
142
142
nil
143
143
end
144
144
145
- if source_fiber_stack
146
- # Use a stack with `.pop` here so that when a source causes another source to become pending,
147
- # that newly-pending source will run _before_ the one that depends on it.
148
- # (See below where the old fiber is pushed to the stack, then the new fiber is pushed on the stack.)
149
- while ( outer_source_fiber = source_fiber_stack . pop )
145
+ if source_fiber_queue
146
+ while ( outer_source_fiber = source_fiber_queue . shift )
150
147
resume ( outer_source_fiber )
151
148
152
- if outer_source_fiber . alive?
153
- source_fiber_stack << outer_source_fiber
154
- end
155
149
# If this source caused more sources to become pending, run those before running this one again:
156
150
next_source_fiber = create_source_fiber
157
151
if next_source_fiber
158
- source_fiber_stack << next_source_fiber
152
+ source_fiber_queue << next_source_fiber
153
+ end
154
+
155
+ if outer_source_fiber . alive?
156
+ source_fiber_queue << outer_source_fiber
159
157
end
160
158
end
161
159
end
@@ -224,16 +222,16 @@ def resume(fiber)
224
222
#
225
223
# @see https://github.com/rmosolgo/graphql-ruby/issues/3449
226
224
def spawn_fiber
227
- fiber_locals = { }
225
+ fiber_locals = { }
228
226
229
227
Thread . current . keys . each do |fiber_var_key |
230
228
fiber_locals [ fiber_var_key ] = Thread . current [ fiber_var_key ]
231
- end
229
+ end
232
230
233
- Fiber . new do
231
+ Fiber . new do
234
232
fiber_locals . each { |k , v | Thread . current [ k ] = v }
235
233
yield
236
- end
234
+ end
237
235
end
238
236
end
239
237
end
0 commit comments