Class: Fear::Promise Private

Inherits:
Concurrent::IVar
  • Object
show all
Defined in:
lib/fear/promise.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Promise

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Promise


13
14
15
16
17
18
19
# File 'lib/fear/promise.rb', line 13

def initialize(**options)
  super()
  @options = options
  @promise = Concurrent::Promise.new(options) do
    Fear.try { value }.flatten
  end
end

Instance Method Details

#complete(result) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with result

Raises:


85
86
87
88
89
90
91
92
93
# File 'lib/fear/promise.rb', line 85

def complete(result)
  if completed?
    false
  else
    set result
    promise.execute
    true
  end
end

#complete!(result) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with result

Raises:


71
72
73
74
75
76
77
# File 'lib/fear/promise.rb', line 71

def complete!(result)
  if complete(result)
    self
  else
    raise IllegalStateException, "Promise already completed."
  end
end

#completed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


24
25
26
# File 'lib/fear/promise.rb', line 24

def completed?
  complete?
end

#failure(error) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with failure

See Also:


54
55
56
# File 'lib/fear/promise.rb', line 54

def failure(error)
  complete(Fear.failure(error))
end

#failure!(error) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with failure

Raises:

See Also:


63
64
65
# File 'lib/fear/promise.rb', line 63

def failure!(error)
  complete!(Fear.failure(error))
end

#success(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with successful result

See Also:


37
38
39
# File 'lib/fear/promise.rb', line 37

def success(value)
  complete(Fear.success(value))
end

#success!(value) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Complete this promise with failure

Raises:

See Also:


46
47
48
# File 'lib/fear/promise.rb', line 46

def success!(value)
  complete!(Fear.success(value))
end

#to_futureFear::Future

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


29
30
31
# File 'lib/fear/promise.rb', line 29

def to_future
  Future.new(promise, options)
end