Class: Dispatch::BackgroundUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/carat-dev/detach/detach.rb

Overview

These are created for each background work unit (method call) that is created. They keep stats and allow for indexing when the value is ready.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ BackgroundUnit

Returns a new instance of BackgroundUnit.



43
44
45
46
47
48
# File 'lib/carat-dev/detach/detach.rb', line 43

def initialize(id)
    @unit_id = id
    @thread = nil
    @start = nil
    @stop = nil
end

Instance Attribute Details

#startObject

Returns the value of attribute start.



40
41
42
# File 'lib/carat-dev/detach/detach.rb', line 40

def start
  @start
end

#stopObject

Returns the value of attribute stop.



40
41
42
# File 'lib/carat-dev/detach/detach.rb', line 40

def stop
  @stop
end

#threadObject

Returns the value of attribute thread.



41
42
43
# File 'lib/carat-dev/detach/detach.rb', line 41

def thread
  @thread
end

#unit_idObject

Returns the value of attribute unit_id.



40
41
42
# File 'lib/carat-dev/detach/detach.rb', line 40

def unit_id
  @unit_id
end

#valueObject

Returns the value of attribute value.



41
42
43
# File 'lib/carat-dev/detach/detach.rb', line 41

def value
  @value
end

Instance Method Details

#elapseObject

Indicates the elapse time spent on the unit



63
64
65
# File 'lib/carat-dev/detach/detach.rb', line 63

def elapse
    @stop - @start
end

#ready?Boolean

Indicates if the unit has finished processing

Returns:

  • (Boolean)


68
69
70
# File 'lib/carat-dev/detach/detach.rb', line 68

def ready?
    !@thread.alive?
end