Class: Redis::Ick::FutureContinuation

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/ick.rb

Overview

A deferred computation which allows us to perform post-processing on results which come back from redis pipelines.

The idea is to regain some measure of composability by allowing utility methods to respond polymorphically depending on whether they are called in a pipeline.

TODO: Where this utility lives in the code is not very well thought-out. This is more broadly applicable than just for Icks. This probably belongs in its own file, or in RedisUtil, or as a monkey-patch into the redis gem. This is intended for use with Redis::Futures, but has zero Redis-specific code. This is more broadly applicable, maybe, than Redis. This is in class Ick for the time being only because Ick.ickstats() is where I first needed this and it isn’t otherwise obvious where to put this.

Instance Method Summary collapse

Constructor Details

#initialize(continuation) ⇒ FutureContinuation

The first (and only the first) time :value is called on this FutureContinuation, conversion will be called.



454
455
456
457
# File 'lib/redis/ick.rb', line 454

def initialize(continuation)
  @continuation = continuation
  @result       = nil
end

Instance Method Details

#valueObject

Force the computation. :value is chosen as the name of this method to be duck-typing compatible with Redis::Future.



462
463
464
465
466
467
468
# File 'lib/redis/ick.rb', line 462

def value
  if @continuation
    @result       = @continuation.call
    @continuation = nil
  end
  @result
end