Class: CLI::UI::WorkQueue::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/ui/work_queue.rb

Instance Method Summary collapse

Constructor Details

#initializeFuture

: -> void



9
10
11
12
13
14
15
16
# File 'lib/cli/ui/work_queue.rb', line 9

def initialize
  @mutex = Mutex.new #: Mutex
  @condition = ConditionVariable.new #: ConditionVariable
  @completed = false #: bool
  @started = false #: bool
  @result = nil #: untyped
  @error = nil #: Exception?
end

Instance Method Details

#complete(result) ⇒ Object

: (untyped result) -> void



19
20
21
22
23
24
25
# File 'lib/cli/ui/work_queue.rb', line 19

def complete(result)
  @mutex.synchronize do
    @completed = true
    @result = result
    @condition.broadcast
  end
end

#completed?Boolean

: -> bool

Returns:

  • (Boolean)


49
50
51
# File 'lib/cli/ui/work_queue.rb', line 49

def completed?
  @mutex.synchronize { @completed }
end

#fail(error) ⇒ Object

: (Exception error) -> void



28
29
30
31
32
33
34
35
36
# File 'lib/cli/ui/work_queue.rb', line 28

def fail(error)
  @mutex.synchronize do
    return if @completed

    @completed = true
    @error = error
    @condition.broadcast
  end
end

#startObject

: -> void



59
60
61
62
63
64
# File 'lib/cli/ui/work_queue.rb', line 59

def start
  @mutex.synchronize do
    @started = true
    @condition.broadcast
  end
end

#started?Boolean

: -> bool

Returns:

  • (Boolean)


54
55
56
# File 'lib/cli/ui/work_queue.rb', line 54

def started?
  @mutex.synchronize { @started }
end

#valueObject

: -> untyped



39
40
41
42
43
44
45
46
# File 'lib/cli/ui/work_queue.rb', line 39

def value
  @mutex.synchronize do
    @condition.wait(@mutex) until @completed
    raise @error if @error

    @result
  end
end