Class: KuberKit::UI::Simple::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/ui/simple.rb

Instance Method Summary collapse

Constructor Details

#initialize(title, &callback) ⇒ Task

Returns a new instance of Task.



3
4
5
6
# File 'lib/kuber_kit/ui/simple.rb', line 3

def initialize(title, &callback)
  @title = title
  @callback = callback
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kuber_kit/ui/simple.rb', line 8

def execute
  if @thread
    raise "Already started execution of task '#{title}'"
  end

  @thread = Thread.new do
    puts "Start task: #{@title.green}"
    @callback.call(self)
    puts "Finish task: #{@title.green}"
  end
end

#update_title(title) ⇒ Object



27
28
29
# File 'lib/kuber_kit/ui/simple.rb', line 27

def update_title(title)
  @title = title
end

#waitObject



20
21
22
23
24
25
# File 'lib/kuber_kit/ui/simple.rb', line 20

def wait
  if !@thread
    raise "Task '#{title}' not started"
  end
  @thread.join
end