Class: EY::Serverside::Future

Inherits:
Object
  • Object
show all
Extended by:
Dataflow
Defined in:
lib/engineyard-serverside/future.rb,
lib/engineyard-serverside/futures/dataflow.rb,
lib/engineyard-serverside/futures/celluloid.rb

Constant Summary

Constants included from Dataflow

Dataflow::UnificationError, Dataflow::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dataflow

barrier, by_need, flow, included, local, need_later, unify

Constructor Details

#initialize(server, *args, &block) ⇒ Future

Returns a new instance of Future.



8
9
10
11
12
# File 'lib/engineyard-serverside/future.rb', line 8

def initialize(server, *args, &block)
  @server = server
  @args = args
  @block = block
end

Class Method Details

.call(servers, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/engineyard-serverside/futures/dataflow.rb', line 9

def self.call(servers, *args, &block)
  futures = []
  # Dataflow needs to call `barrier` and `need_later` in the same object
  barrier(*servers.map do |server|
    future = new(server, *args, &block)
    futures << future

    need_later { future.call }
  end)

  futures
end

.success?(futures) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/engineyard-serverside/future.rb', line 4

def self.success?(futures)
  futures.empty? || futures.all? {|f| f.success?}
end

Instance Method Details

#callObject



26
27
28
# File 'lib/engineyard-serverside/futures/dataflow.rb', line 26

def call
  @value ||= future
end

#error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/engineyard-serverside/future.rb', line 18

def error?
  !success?
end

#futureObject



22
23
24
# File 'lib/engineyard-serverside/futures/dataflow.rb', line 22

def future
  @block.call(@server, *@args)
end

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/engineyard-serverside/future.rb', line 14

def success?
  @value == true
end