lib/graphql/dataloader.rb in graphql-1.12.4 vs lib/graphql/dataloader.rb in graphql-1.12.5

- old
+ new

@@ -93,11 +93,11 @@ if first_pass first_pass = false else # These fibers were previously waiting for sources to load data, # resume them. (They might wait again, in which case, re-enqueue them.) - f.resume + resume(f) if f.alive? next_fibers << f end end @@ -107,14 +107,11 @@ f = Fiber.new { while (job = @pending_jobs.shift) job.call end } - result = f.resume - if result.is_a?(StandardError) - raise result - end + resume(f) # In this case, the job yielded. Queue it up to run again after # we load whatever it's waiting for. if f.alive? next_fibers << f end @@ -136,14 +133,11 @@ if source_fiber_stack # Use a stack with `.pop` here so that when a source causes another source to become pending, # that newly-pending source will run _before_ the one that depends on it. # (See below where the old fiber is pushed to the stack, then the new fiber is pushed on the stack.) while (outer_source_fiber = source_fiber_stack.pop) - result = outer_source_fiber.resume - if result.is_a?(StandardError) - raise result - end + resume(outer_source_fiber) if outer_source_fiber.alive? source_fiber_stack << outer_source_fiber end # If this source caused more sources to become pending, run those before running this one again: @@ -201,8 +195,14 @@ pending_sources.each(&:run_pending_keys) end end source_fiber + end + + def resume(fiber) + fiber.resume + rescue UncaughtThrowError => e + throw e.tag, e.value end end end