Method: Concurrent::Promises::Future#run

Defined in:
lib/concurrent-ruby/concurrent/promises.rb

#run(run_test = method(:run_test)) ⇒ Future

Allows to use futures as green threads. The receiver has to evaluate to a future which represents what should be done next. It basically flattens indefinitely until non Future values is returned which becomes result of the returned future. Any encountered exception will become reason of the returned future.

Examples:

body = lambda do |v|
  v += 1
  v < 5 ? Promises.future(v, &body) : v
end
Promises.future(0, &body).run.value! # => 5

Parameters:

  • run_test (#call(value)) (defaults to: method(:run_test))

    an object which when called returns either Future to keep running with or nil, then the run completes with the value. The run_test can be used to extract the Future from deeper structure, or to distinguish Future which is a resulting value from a future which is suppose to continue running.

Returns:



1199
1200
1201
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1199

def run(run_test = method(:run_test))
  RunFuturePromise.new_blocked_by1(self, @DefaultExecutor, run_test).future
end