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.

Parameters:

  • options (Hash)

    options passed to underlying Concurrent::Promise



7
8
9
10
11
12
13
# File 'lib/fear/promise.rb', line 7

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

Parameters:

Returns:

  • (Boolean)

    If the promise has already been completed returns ‘false`, or `true` otherwise.

Raises:



79
80
81
82
83
84
85
86
87
# File 'lib/fear/promise.rb', line 79

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

Parameters:

Returns:

  • (self)

Raises:



65
66
67
68
69
70
71
# File 'lib/fear/promise.rb', line 65

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.

Returns:

  • (Boolean)


18
19
20
# File 'lib/fear/promise.rb', line 18

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

Parameters:

  • error (StandardError)

Returns:

  • (Boolean)

See Also:



48
49
50
# File 'lib/fear/promise.rb', line 48

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

Parameters:

  • error (StandardError)

Returns:

  • (self)

Raises:

See Also:



57
58
59
# File 'lib/fear/promise.rb', line 57

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

Parameters:

  • value (any)

Returns:

  • (Boolean)

See Also:



31
32
33
# File 'lib/fear/promise.rb', line 31

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 value

Parameters:

  • value (any)

Returns:

  • (self)

Raises:

See Also:



40
41
42
# File 'lib/fear/promise.rb', line 40

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.

Returns:



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

def to_future
  Future.new(promise, **options)
end