lib/graphql/dataloader.rb in graphql-1.12.11 vs lib/graphql/dataloader.rb in graphql-1.12.12
- old
+ new
@@ -75,9 +75,24 @@
# (If the dataloader is already running, than a Fiber will pick this up later.)
@pending_jobs.push(job)
nil
end
+ # Use a self-contained queue for the work in the block.
+ def run_isolated
+ prev_queue = @pending_jobs
+ @pending_jobs = []
+ res = nil
+ # Make sure the block is inside a Fiber, so it can `Fiber.yield`
+ append_job {
+ res = yield
+ }
+ run
+ res
+ ensure
+ @pending_jobs = prev_queue
+ end
+
# @api private Move along, move along
def run
# At a high level, the algorithm is:
#
# A) Inside Fibers, run jobs from the queue one-by-one