Class: Valkey::Future

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

Overview

A placeholder for the reply to a command queued inside Valkey#pipelined or the block form of Valkey::Commands::TransactionCommands#multi.

Deliberately a plain Object, not BasicObject (unlike redis-rb's Redis::Future): #value is always called explicitly by callers, never as a transparent proxy, so BasicObject's stripped-down method surface buys nothing here.

Coercion (Utils::Boolify, etc.) is intentionally not duplicated here: by the time Pipeline#resolve_futures! calls #_set, send_batch_commands has already applied it to the corresponding results.

Instance Method Summary collapse

Constructor Details

#initialize(command_type, command_args) ⇒ Future

Returns a new instance of Future.



41
42
43
44
45
46
# File 'lib/valkey/future.rb', line 41

def initialize(command_type, command_args)
  @command_type = command_type
  @command_args = command_args
  @object = NOT_READY
  @aborted = false
end

Instance Method Details

#_abort!Object

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.



54
55
56
# File 'lib/valkey/future.rb', line 54

def _abort!
  @aborted = true if @object.equal?(NOT_READY)
end

#_set(object) ⇒ Object

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.



49
50
51
# File 'lib/valkey/future.rb', line 49

def _set(object)
  @object = object
end

#inspectObject



81
82
83
# File 'lib/valkey/future.rb', line 81

def inspect
  "#<Valkey::Future #{@command_type.inspect} #{@command_args.inspect}>"
end

#ready?Boolean

Returns whether #value can be called right now without raising FutureNotReady/FutureAborted.

Returns:

  • (Boolean)

    whether #value can be called right now without raising FutureNotReady/FutureAborted.



60
61
62
# File 'lib/valkey/future.rb', line 60

def ready?
  !@aborted && !@object.equal?(NOT_READY)
end

#valueObject

Returns the resolved reply, already coerced the same way a live (non-pipelined) call to the same command would be.

Returns:

  • (Object)

    the resolved reply, already coerced the same way a live (non-pipelined) call to the same command would be.

Raises:

  • (FutureAborted)

    if the owning pipeline never got to resolve this command (block raised, or the batch failed partway through)

  • (FutureNotReady)

    if called before the pipeline/multi block has returned and its batch has been sent

  • (CommandError)

    if this slot's reply was itself an inline error (e.g. WRONGTYPE inside a batch) - matches Valkey#convert_response's "no rollback on runtime error" semantics.



73
74
75
76
77
78
79
# File 'lib/valkey/future.rb', line 73

def value
  raise FutureAborted if @aborted
  raise FutureNotReady if @object.equal?(NOT_READY)
  raise @object if @object.is_a?(StandardError)

  @object
end