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 redis-rb. 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.



425
426
427
428
# File 'lib/redis/ick.rb', line 425

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.



433
434
435
436
437
438
439
# File 'lib/redis/ick.rb', line 433

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