Class: Boogaloo::WorkerThread

Inherits:
Thread
  • Object
show all
Defined in:
lib/boogaloo/worker_thread.rb

Overview

Handles method calls to a service instance in a thread.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ WorkerThread

Initialize a new WorkerThread instance.



7
8
9
10
11
12
# File 'lib/boogaloo/worker_thread.rb', line 7

def initialize

    super {}
    @obj = nil

end

Instance Method Details

#perform(meth, *a, &b) ⇒ Object

Perform method calls on the service instance.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/boogaloo/worker_thread.rb', line 26

def perform(meth, *a, &b)

    ret = nil
    
    begin
    
        ret = @obj.send(meth, *a)
    
    rescue NoMethodError, TypeError => e
    
        return e
    
    end

    ret

end

#use_instance(obj) ⇒ Object

Tells the WorkerThread to forward method calls to the given service instance.

Parameters:

obj

The service instance to forward to.



19
20
21
22
23
# File 'lib/boogaloo/worker_thread.rb', line 19

def use_instance(obj)

    @obj = obj

end