Class: BulkOperations::UnorderedBulkProxy

Inherits:
BulkProxy
  • Object
show all
Defined in:
lib/bulk_operations/unordered_bulk.rb

Instance Attribute Summary

Attributes inherited from BulkProxy

#proxied_object

Instance Method Summary collapse

Methods inherited from BulkProxy

#execute, #initialize, #method_missing

Constructor Details

This class inherits a constructor from BulkOperations::BulkProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BulkOperations::BulkProxy

Instance Method Details

#do_executeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bulk_operations/unordered_bulk.rb', line 3

def do_execute
  result = Hash.new
  threads = []

  @operation_stack.each do |operation|
    name, *args, block = *operation
    threads << spawn_thread(name, args, block, result)
  end

  threads.each(&:join)

  StructResult.new result
end

#spawn_thread(name, args, block, result) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bulk_operations/unordered_bulk.rb', line 17

def spawn_thread(name, args, block, result)
  thread = Thread.new do
    begin
      call_result = @proxied_object.__send__(name, *args, &block)
      result[name] = { ok: true, result: call_result }
    rescue => exception
      result[name] = { ok: false, result: exception }
    end
  end

  thread
end