Class: GraphQL::Dataloader::AsyncDataloader
- Inherits:
-
GraphQL::Dataloader
- Object
- GraphQL::Dataloader
- GraphQL::Dataloader::AsyncDataloader
- Defined in:
- lib/graphql/dataloader/async_dataloader.rb
Constant Summary
Constants inherited from GraphQL::Dataloader
Instance Method Summary collapse
Methods inherited from GraphQL::Dataloader
#append_job, #clear_cache, #get_fiber_variables, #initialize, #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
10 11 12 13 14 15 16 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 |
# File 'lib/graphql/dataloader/async_dataloader.rb', line 10 def run job_tasks = [] next_job_tasks = [] source_tasks = [] next_source_tasks = [] first_pass = true jobs_condition = Async::Condition.new sources_condition = Async::Condition.new Sync do |root_task| while first_pass || job_tasks.any? first_pass = false while (task = job_tasks.shift || spawn_job_task(root_task, jobs_condition)) if task.alive? next_job_tasks << task elsif task.failed? # re-raise a raised error - # this also covers errors from sources since # these jobs wait for sources as needed. task.wait end end root_task.yield # give job tasks a chance to run job_tasks.concat(next_job_tasks) next_job_tasks.clear while source_tasks.any? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) } while (task = source_tasks.shift || spawn_source_task(root_task, sources_condition)) if task.alive? next_source_tasks << task end end root_task.yield # give source tasks a chance to run sources_condition.signal source_tasks.concat(next_source_tasks) next_source_tasks.clear end jobs_condition.signal end end rescue UncaughtThrowError => e throw e.tag, e.value end |
#yield ⇒ Object
5 6 7 8 |
# File 'lib/graphql/dataloader/async_dataloader.rb', line 5 def yield Thread.current[:graphql_dataloader_next_tick].wait nil end |