Class: Valkey::Future
- Inherits:
-
Object
- Object
- Valkey::Future
- 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
- #_abort! ⇒ Object private
- #_set(object) ⇒ Object private
-
#initialize(command_type, command_args) ⇒ Future
constructor
A new instance of Future.
- #inspect ⇒ Object
-
#ready? ⇒ Boolean
Whether #value can be called right now without raising FutureNotReady/FutureAborted.
-
#value ⇒ Object
The resolved reply, already coerced the same way a live (non-pipelined) call to the same command would be.
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 |
#inspect ⇒ Object
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.
60 61 62 |
# File 'lib/valkey/future.rb', line 60 def ready? !@aborted && !@object.equal?(NOT_READY) end |
#value ⇒ Object
Returns the resolved reply, already coerced the same way a live (non-pipelined) call to the same command would be.
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 |