Class: Actor::Substitutes::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/actor/substitutes/thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Thread

Returns a new instance of Thread.



9
10
11
12
13
14
# File 'lib/actor/substitutes/thread.rb', line 9

def initialize &block
  @status = 'run'
  @priority = 0

  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/actor/substitutes/thread.rb', line 4

def block
  @block
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/actor/substitutes/thread.rb', line 5

def name
  @name
end

#priorityObject

Returns the value of attribute priority.



6
7
8
# File 'lib/actor/substitutes/thread.rb', line 6

def priority
  @priority
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/actor/substitutes/thread.rb', line 7

def status
  @status
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/actor/substitutes/thread.rb', line 30

def alive?
  %w(sleep run).include? status
end

#join(limit = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/actor/substitutes/thread.rb', line 16

def join limit=nil
  if limit
    begin
      Timeout.timeout limit, &block
    rescue Timeout::Error
      return nil
    end
  else
    block.()
  end

  self
end

#stop?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/actor/substitutes/thread.rb', line 34

def stop?
  status != 'run'
end