Class: Google::Cloud::Firestore::Promise::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/firestore/promise/future.rb

Overview

Future

A Future object represents a value which will become available in future. May reject with a reason instead, e.g. when the tasks raises an exception.

Instance Method Summary collapse

Constructor Details

#initialize(future) ⇒ Future

Initialize the future object



29
30
31
# File 'lib/google/cloud/firestore/promise/future.rb', line 29

def initialize future
  @future = future
end

Instance Method Details

#fulfilled?Boolean

Is it in fulfilled state?

Returns:

  • (Boolean)


36
37
38
# File 'lib/google/cloud/firestore/promise/future.rb', line 36

def fulfilled?
  @future.fulfilled?
end

#reason(timeout = nil, timeout_value = nil) ⇒ Object, timeout_value

Returns reason of future's rejection.

Returns:

  • (Object, timeout_value)

    the reason, or timeout_value on timeout, or nil on fulfillment.



62
63
64
# File 'lib/google/cloud/firestore/promise/future.rb', line 62

def reason timeout = nil, timeout_value = nil
  @future.reason timeout, timeout_value
end

#rejected?Boolean

Is it in rejected state?

Returns:

  • (Boolean)


43
44
45
# File 'lib/google/cloud/firestore/promise/future.rb', line 43

def rejected?
  @future.rejected?
end

#rescue(*args) {|reason, *args| ... } ⇒ Future

Chains the task to be executed synchronously on executor after it rejects. Does not run the task if it fulfills. It will resolve though, triggering any dependent futures.

Yields:

  • (reason, *args)

    to the task.

Returns:



90
91
92
# File 'lib/google/cloud/firestore/promise/future.rb', line 90

def rescue *args, &task
  Future.new @future.rescue(*args, &task)
end

#then(*args) {|reason, *args| ... } ⇒ Future

Chains the task to be executed synchronously after it fulfills. Does not run the task if it rejects. It will resolve though, triggering any dependent futures.

Yields:

  • (reason, *args)

    to the task.

Returns:



80
81
82
# File 'lib/google/cloud/firestore/promise/future.rb', line 80

def then *args, &task
  Future.new @future.then(*args, &task)
end

#value(timeout = nil, timeout_value = nil) ⇒ Object, ...

Method waits for the timeout duration and return the value of the future if fulfilled, timeout value in case of timeout and nil in case of rejection.

Parameters:

  • timeout (Integer) (defaults to: nil)

    the maximum time in seconds to wait

  • timeout_value (Object) (defaults to: nil)

    a value returned by the method when it times out

Returns:

  • (Object, nil, timeout_value)

    the value of the Future when fulfilled, timeout_value on timeout, nil on rejection.



55
56
57
# File 'lib/google/cloud/firestore/promise/future.rb', line 55

def value timeout = nil, timeout_value = nil
  @future.value timeout, timeout_value
end

#wait!(timeout = nil) ⇒ Object

Method waits for the timeout duration and raise exception on rejection

Parameters:

  • timeout (Integer) (defaults to: nil)

    the maximum time in seconds to wait



70
71
72
# File 'lib/google/cloud/firestore/promise/future.rb', line 70

def wait! timeout = nil
  @future.wait! timeout
end