Method: ReactiveRecord.load

Defined in:
lib/reactive_record/active_record/reactive_record/while_loading.rb

.load(&block) ⇒ Object

will repeatedly execute the block until it is loaded immediately returns a promise that will resolve once the block is loaded



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/reactive_record/active_record/reactive_record/while_loading.rb', line 12

def self.load(&block)
  promise = Promise.new
  @load_stack ||= []
  @load_stack << @loads_pending
  @loads_pending = nil
  result = block.call.itself
  if @loads_pending
    @blocks_to_load ||= []
    @blocks_to_load << [Base.last_fetch_at, promise, block]
  else
    promise.resolve result
  end
  @loads_pending = @load_stack.pop
  promise
rescue Exception => e
  React::IsomorphicHelpers.log "ReactiveRecord.load exception raised during initial load: #{e}", :error
end