Class: GraphQL::Dataloader::AsyncDataloader
- Inherits:
- 
      GraphQL::Dataloader
      
        - Object
- GraphQL::Dataloader
- GraphQL::Dataloader::AsyncDataloader
 
- Defined in:
- lib/graphql/dataloader/async_dataloader.rb
Instance Attribute Summary
Attributes inherited from GraphQL::Dataloader
Instance Method Summary collapse
Methods inherited from GraphQL::Dataloader
#append_job, #cleanup_fiber, #clear_cache, #get_fiber_variables, #initialize, #merge_records, #nonblocking?, #run_fiber, #run_isolated, #set_fiber_variables, #spawn_fiber, use, #with, with_dataloading
Constructor Details
This class inherits a constructor from GraphQL::Dataloader
Instance Method Details
#run ⇒ Object
| 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # File 'lib/graphql/dataloader/async_dataloader.rb', line 17 def run trace = Fiber[:__graphql_current_multiplex]&.current_trace jobs_fiber_limit, total_fiber_limit = calculate_fiber_limit job_fibers = [] next_job_fibers = [] source_tasks = [] next_source_tasks = [] first_pass = true sources_condition = Async::Condition.new manager = spawn_fiber do trace&.begin_dataloader(self) while first_pass || !job_fibers.empty? first_pass = false fiber_vars = get_fiber_variables while (f = (job_fibers.shift || (((job_fibers.size + next_job_fibers.size + source_tasks.size) < jobs_fiber_limit) && spawn_job_fiber(trace)))) if f.alive? finished = run_fiber(f) if !finished next_job_fibers << f end end end job_fibers.concat(next_job_fibers) next_job_fibers.clear Sync do |root_task| set_fiber_variables(fiber_vars) while !source_tasks.empty? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) } while (task = (source_tasks.shift || (((job_fibers.size + next_job_fibers.size + source_tasks.size + next_source_tasks.size) < total_fiber_limit) && spawn_source_task(root_task, sources_condition, trace)))) if task.alive? root_task.yield # give the source task a chance to run next_source_tasks << task end end sources_condition.signal source_tasks.concat(next_source_tasks) next_source_tasks.clear end end end trace&.end_dataloader(self) end manager.resume if manager.alive? raise "Invariant: Manager didn't terminate successfully: #{manager}" end rescue UncaughtThrowError => e throw e.tag, e.value end | 
#yield(source = Fiber[:__graphql_current_dataloader_source]) ⇒ Object
| 5 6 7 8 9 10 11 12 13 14 15 | # File 'lib/graphql/dataloader/async_dataloader.rb', line 5 def yield(source = Fiber[:__graphql_current_dataloader_source]) trace = Fiber[:__graphql_current_multiplex]&.current_trace trace&.dataloader_fiber_yield(source) if (condition = Fiber[:graphql_dataloader_next_tick]) condition.wait else Fiber.yield end trace&.dataloader_fiber_resume(source) nil end |