Class: LazyData::InternalState

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_data/internal_state.rb

Overview

A representation of the internal state of a Value.

Constant Summary collapse

FAILED =

The FAILED state indicates that computation has failed finally and no more retries will be done. If the state is FAILED, and error will be present and the value will be nil. The expires_at time will be a CLOCK_MONOTONIC timestamp if the failure can expire, or nil if not.

:failed
SUCCESS =

The SUCCESS state indicates that computation has completed successfully, and the value is set. The error will be nil. The expires_at time will be a CLOCK_MONOTONIC timestamp if the value can expire, or nil if not.

:success
PENDING =

The PENDING state indicates the value has not been computed, or that previous computation attempts have failed but there are retries pending. The error will be set to the most recent error, or nil if no computation attempt has yet been started. The value will be nil. The expires_at time will be the CLOCK_MONOTONIC timestamp when the current retry delay will end (or has ended, so it could be in the past), or nil if there are no retry delays.

:pending
COMPUTING =

The COMPUTING state indicates that a thread is currently computing the value. The error and value will both be nil. The expires_at time will be the CLOCK_MONOTONIC timestamp when the computation had started.

:computing

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorException? (readonly)

The last computation error, if the state is FAILED or PENDING, otherwise nil.

Returns:

  • (Exception, nil)


77
78
79
# File 'lib/lazy_data/internal_state.rb', line 77

def error
  @error
end

#expires_atNumeric? (readonly)

The CLOCK_MONOTONIC timestamp of expiration, or the start of the current computation when in COMPUTING state.

Returns:

  • (Numeric, nil)


85
86
87
# File 'lib/lazy_data/internal_state.rb', line 85

def expires_at
  @expires_at
end

#stateSymbol (readonly)

The general state of the value. Will be PENDING, COMPUTING, SUCCESS, or FAILED.

Returns:

  • (Symbol)


61
62
63
# File 'lib/lazy_data/internal_state.rb', line 61

def state
  @state
end

#valueObject (readonly)

The current computed value, if the state is SUCCESS, or nil for any other state

Returns:

  • (Object)


69
70
71
# File 'lib/lazy_data/internal_state.rb', line 69

def value
  @value
end

Instance Method Details

#computing?boolean

Query whether the state is computing

Returns:

  • (boolean)


119
120
121
# File 'lib/lazy_data/internal_state.rb', line 119

def computing?
  state == COMPUTING
end

#failed?boolean

Query whether the state is failure

Returns:

  • (boolean)


92
93
94
# File 'lib/lazy_data/internal_state.rb', line 92

def failed?
  state == FAILED
end

#pending?boolean

Query whether the state is pending

Returns:

  • (boolean)


110
111
112
# File 'lib/lazy_data/internal_state.rb', line 110

def pending?
  state == PENDING
end

#success?boolean

Query whether the state is success

Returns:

  • (boolean)


101
102
103
# File 'lib/lazy_data/internal_state.rb', line 101

def success?
  state == SUCCESS
end