Class: Core::Async::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/core/async/future.rb

Overview

public

Represents a future result.

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Future

Returns a new instance of Future.



8
9
10
11
# File 'lib/core/async/future.rb', line 8

def initialize(task)
  @task = task
  @error = nil
end

Instance Method Details

#complete?Boolean

public

Return true if complete.

Returns:

  • (Boolean)


96
97
98
# File 'lib/core/async/future.rb', line 96

def complete?
  status == :complete
end

#errorObject

public

Return any error that occurred without re-raising, blocking until available.



41
42
43
# File 'lib/core/async/future.rb', line 41

def error
  @error ||= get_error
end

#failed?Boolean

public

Return true if failed.

Returns:

  • (Boolean)


90
91
92
# File 'lib/core/async/future.rb', line 90

def failed?
  status == :failed
end

#pending?Boolean

public

Return true if pending.

Returns:

  • (Boolean)


84
85
86
# File 'lib/core/async/future.rb', line 84

def pending?
  status == :pending
end

#resolved?Boolean

public

Return true if failed or complete.

Returns:

  • (Boolean)


102
103
104
# File 'lib/core/async/future.rb', line 102

def resolved?
  failed? || complete?
end

#resultObject

public

Return the result, blocking until available.



25
26
27
# File 'lib/core/async/future.rb', line 25

def result
  @error || @result ||= resolve
end

#statusObject

public

Return the status; one of :pending, :failed, or :complete.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/core/async/future.rb', line 54

def status
  if defined?(@status)
    @status
  else
    status = find_status
    if terminal_status?(status)
      @status = status
    end

    status
  end
end

#waitObject

public

Wait on the task to complete, returning self.



15
16
17
18
19
20
21
# File 'lib/core/async/future.rb', line 15

def wait
  unless @error
    resolve
  end

  self
end