Module: Concurrent::Promises::FactoryMethods
- Extended by:
- FactoryMethods, ReInclude
- Includes:
- Configuration
- Included in:
- Concurrent::Promises, FactoryMethods, Throttle
- Defined in:
- lib/concurrent-ruby/concurrent/promises.rb,
lib/concurrent-ruby-edge/concurrent/edge/promises.rb,
lib/concurrent-ruby-edge/concurrent/edge/old_channel_integration.rb
Overview
Defined Under Namespace
Modules: Configuration
Class Method Summary collapse
-
.any_event(*futures_and_or_events) ⇒ Future
Shortcut of #any_event_on with default
:io
executor supplied. -
.any_event_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which becomes resolved after first of the futures_and_or_events resolves.
-
.any_fulfilled_future(*futures_and_or_events) ⇒ Future
Shortcut of #any_fulfilled_future_on with default
:io
executor supplied. -
.any_fulfilled_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first of futures_and_or_events is fulfilled.
-
.any_resolved_future(*futures_and_or_events) ⇒ Future
(also: #any)
Shortcut of #any_resolved_future_on with default
:io
executor supplied. -
.any_resolved_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first futures_and_or_events is resolved.
-
.delay(*args, &task) ⇒ Future, Event
Shortcut of #delay_on with default
:io
executor supplied. -
.delay_on(default_executor, *args, &task) ⇒ undocumented
Creates new event or future which is resolved only after it is touched, see AbstractEventFuture#touch.
-
.fulfilled_future(value, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be fulfilled with the given value.
-
.future(*args, &task) ⇒ Future
Shortcut of #future_on with default
:io
executor supplied. -
.future_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor.
-
.make_future(argument = nil, default_executor = self.default_executor) ⇒ Event, Future
General constructor.
-
.rejected_future(reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be rejected with the given reason.
-
.resolvable_event ⇒ ResolvableEvent
Shortcut of #resolvable_event_on with default
:io
executor supplied. -
.resolvable_event_on(default_executor = self.default_executor) ⇒ ResolvableEvent
Created resolvable event, user is responsible for resolving the event once by ResolvableEvent#resolve.
-
.resolvable_future ⇒ ResolvableFuture
Shortcut of #resolvable_future_on with default
:io
executor supplied. -
.resolvable_future_on(default_executor = self.default_executor) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject.
-
.resolved_event(default_executor = self.default_executor) ⇒ Event
Creates resolved event.
-
.resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be either fulfilled with the given value or rejection with the given reason.
-
.schedule(intended_time, *args, &task) ⇒ Future, Event
Shortcut of #schedule_on with default
:io
executor supplied. -
.schedule_on(default_executor, intended_time, *args, &task) ⇒ undocumented
Creates new event or future which is resolved in intended_time.
-
.zip_events(*futures_and_or_events) ⇒ Event
Shortcut of #zip_events_on with default
:io
executor supplied. -
.zip_events_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which is resolved after all futures_and_or_events are resolved.
-
.zip_futures(*futures_and_or_events) ⇒ Future
(also: #zip)
Shortcut of #zip_futures_on with default
:io
executor supplied. -
.zip_futures_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after all futures_and_or_events are resolved.
-
.zip_futures_over(enumerable, &future_factory) ⇒ Future
Shortcut of #zip_futures_over_on with default
:io
executor supplied. -
.zip_futures_over_on(default_executor, enumerable) {|element| ... } ⇒ Future
Creates new future which is resolved after all the futures created by future_factory from enumerable elements are resolved.
-
.default_executor ⇒ Executor, :io, :fast
extended
from Configuration
The executor which is used when none is supplied to a factory method.
Instance Method Summary collapse
-
#any_event(*futures_and_or_events) ⇒ Future
Shortcut of #any_event_on with default
:io
executor supplied. -
#any_event_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which becomes resolved after first of the futures_and_or_events resolves.
-
#any_fulfilled_future(*futures_and_or_events) ⇒ Future
Shortcut of #any_fulfilled_future_on with default
:io
executor supplied. -
#any_fulfilled_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first of futures_and_or_events is fulfilled.
-
#any_resolved_future(*futures_and_or_events) ⇒ Future
(also: #any)
Shortcut of #any_resolved_future_on with default
:io
executor supplied. -
#any_resolved_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first futures_and_or_events is resolved.
-
#delay(*args, &task) ⇒ Future, Event
Shortcut of #delay_on with default
:io
executor supplied. -
#delay_on(default_executor, *args, &task) ⇒ undocumented
Creates new event or future which is resolved only after it is touched, see AbstractEventFuture#touch.
-
#fulfilled_future(value, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be fulfilled with the given value.
-
#future(*args, &task) ⇒ Future
Shortcut of #future_on with default
:io
executor supplied. -
#future_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor.
-
#make_future(argument = nil, default_executor = self.default_executor) ⇒ Event, Future
General constructor.
-
#rejected_future(reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be rejected with the given reason.
-
#resolvable_event ⇒ ResolvableEvent
Shortcut of #resolvable_event_on with default
:io
executor supplied. -
#resolvable_event_on(default_executor = self.default_executor) ⇒ ResolvableEvent
Created resolvable event, user is responsible for resolving the event once by ResolvableEvent#resolve.
-
#resolvable_future ⇒ ResolvableFuture
Shortcut of #resolvable_future_on with default
:io
executor supplied. -
#resolvable_future_on(default_executor = self.default_executor) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject.
-
#resolved_event(default_executor = self.default_executor) ⇒ Event
Creates resolved event.
-
#resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be either fulfilled with the given value or rejection with the given reason.
-
#schedule(intended_time, *args, &task) ⇒ Future, Event
Shortcut of #schedule_on with default
:io
executor supplied. -
#schedule_on(default_executor, intended_time, *args, &task) ⇒ undocumented
Creates new event or future which is resolved in intended_time.
-
#zip_events(*futures_and_or_events) ⇒ Event
Shortcut of #zip_events_on with default
:io
executor supplied. -
#zip_events_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which is resolved after all futures_and_or_events are resolved.
-
#zip_futures(*futures_and_or_events) ⇒ Future
(also: #zip)
Shortcut of #zip_futures_on with default
:io
executor supplied. -
#zip_futures_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after all futures_and_or_events are resolved.
-
#zip_futures_over(enumerable, &future_factory) ⇒ Future
Shortcut of #zip_futures_over_on with default
:io
executor supplied. -
#zip_futures_over_on(default_executor, enumerable) {|element| ... } ⇒ Future
Creates new future which is resolved after all the futures created by future_factory from enumerable elements are resolved.
-
#default_executor ⇒ Executor, :io, :fast
included
from Configuration
The executor which is used when none is supplied to a factory method.
Class Method Details
.any_event(*futures_and_or_events) ⇒ Future
Shortcut of #any_event_on with default :io
executor supplied.
317 318 319 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 317 def any_event(*futures_and_or_events) any_event_on default_executor, *futures_and_or_events end |
.any_event_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which becomes resolved after first of the futures_and_or_events resolves. If resolved it does not propagate AbstractEventFuture#touch, leaving delayed futures un-executed if they are not required any more.
327 328 329 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 327 def any_event_on(default_executor, *futures_and_or_events) AnyResolvedEventPromise.new_blocked_by(futures_and_or_events, default_executor).event end |
.any_fulfilled_future(*futures_and_or_events) ⇒ Future
Shortcut of #any_fulfilled_future_on with default :io
executor supplied.
298 299 300 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 298 def any_fulfilled_future(*futures_and_or_events) any_fulfilled_future_on default_executor, *futures_and_or_events end |
.any_fulfilled_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first of futures_and_or_events is fulfilled.
Its result equals result of the first resolved future or if all futures_and_or_events reject,
it has reason of the last resolved future.
If resolved it does not propagate AbstractEventFuture#touch, leaving delayed
futures un-executed if they are not required any more.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
311 312 313 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 311 def any_fulfilled_future_on(default_executor, *futures_and_or_events) AnyFulfilledFuturePromise.new_blocked_by(futures_and_or_events, default_executor).future end |
.any_resolved_future(*futures_and_or_events) ⇒ Future Also known as: any
Shortcut of #any_resolved_future_on with default :io
executor supplied.
276 277 278 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 276 def any_resolved_future(*futures_and_or_events) any_resolved_future_on default_executor, *futures_and_or_events end |
.any_resolved_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first futures_and_or_events is resolved.
Its result equals result of the first resolved future.
If resolved it does not propagate AbstractEventFuture#touch, leaving delayed
futures un-executed if they are not required any more.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
292 293 294 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 292 def any_resolved_future_on(default_executor, *futures_and_or_events) AnyResolvedFuturePromise.new_blocked_by(futures_and_or_events, default_executor).future end |
.delay(*args, &task) ⇒ Future, Event
Shortcut of #delay_on with default :io
executor supplied.
188 189 190 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 188 def delay(*args, &task) delay_on default_executor, *args, &task end |
#delay_on(default_executor, *args) {|*args| ... } ⇒ Future #delay_on(default_executor) ⇒ Event
Creates new event or future which is resolved only after it is touched, see AbstractEventFuture#touch.
205 206 207 208 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 205 def delay_on(default_executor, *args, &task) event = DelayPromise.new(default_executor).event task ? event.chain(*args, &task) : event end |
.fulfilled_future(value, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be fulfilled with the given value.
125 126 127 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 125 def fulfilled_future(value, default_executor = self.default_executor) resolved_future true, value, nil, default_executor end |
.future(*args, &task) ⇒ Future
Shortcut of #future_on with default :io
executor supplied.
92 93 94 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 92 def future(*args, &task) future_on(default_executor, *args, &task) end |
.future_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor. Evaluation begins immediately.
104 105 106 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 104 def future_on(default_executor, *args, &task) ImmediateEventPromise.new(default_executor).future.then(*args, &task) end |
#make_future(nil, default_executor = self.default_executor) ⇒ Event #make_future(a_future, default_executor = self.default_executor) ⇒ Future #make_future(an_event, default_executor = self.default_executor) ⇒ Event #make_future(exception, default_executor = self.default_executor) ⇒ Future #make_future(value, default_executor = self.default_executor) ⇒ Future
General constructor. Behaves differently based on the argument's type. It's provided for convenience but it's better to be explicit.
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 172 def make_future(argument = nil, default_executor = self.default_executor) case argument when AbstractEventFuture # returning wrapper would change nothing argument when Exception rejected_future argument, default_executor when nil resolved_event default_executor else fulfilled_future argument, default_executor end end |
.rejected_future(reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be rejected with the given reason.
134 135 136 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 134 def rejected_future(reason, default_executor = self.default_executor) resolved_future false, nil, reason, default_executor end |
.resolvable_event ⇒ ResolvableEvent
Shortcut of #resolvable_event_on with default :io
executor supplied.
61 62 63 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 61 def resolvable_event resolvable_event_on default_executor end |
.resolvable_event_on(default_executor = self.default_executor) ⇒ ResolvableEvent
Created resolvable event, user is responsible for resolving the event once by ResolvableEvent#resolve.
70 71 72 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 70 def resolvable_event_on(default_executor = self.default_executor) ResolvableEventPromise.new(default_executor).future end |
.resolvable_future ⇒ ResolvableFuture
Shortcut of #resolvable_future_on with default :io
executor supplied.
76 77 78 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 76 def resolvable_future resolvable_future_on default_executor end |
.resolvable_future_on(default_executor = self.default_executor) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject
86 87 88 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 86 def resolvable_future_on(default_executor = self.default_executor) ResolvableFuturePromise.new(default_executor).future end |
.resolved_event(default_executor = self.default_executor) ⇒ Event
Creates resolved event.
142 143 144 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 142 def resolved_event(default_executor = self.default_executor) ImmediateEventPromise.new(default_executor).event end |
.resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be either fulfilled with the given value or rejection with the given reason.
116 117 118 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 116 def resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ImmediateFuturePromise.new(default_executor, fulfilled, value, reason).future end |
.schedule(intended_time, *args, &task) ⇒ Future, Event
Shortcut of #schedule_on with default :io
executor supplied.
212 213 214 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 212 def schedule(intended_time, *args, &task) schedule_on default_executor, intended_time, *args, &task end |
#schedule_on(default_executor, intended_time, *args) {|*args| ... } ⇒ Future #schedule_on(default_executor, intended_time) ⇒ Event
Creates new event or future which is resolved in intended_time.
231 232 233 234 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 231 def schedule_on(default_executor, intended_time, *args, &task) event = ScheduledPromise.new(default_executor, intended_time).event task ? event.chain(*args, &task) : event end |
.zip_events(*futures_and_or_events) ⇒ Event
Shortcut of #zip_events_on with default :io
executor supplied.
260 261 262 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 260 def zip_events(*futures_and_or_events) zip_events_on default_executor, *futures_and_or_events end |
.zip_events_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which is resolved after all futures_and_or_events are resolved. (Future is resolved when fulfilled or rejected.)
270 271 272 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 270 def zip_events_on(default_executor, *futures_and_or_events) ZipEventsPromise.new_blocked_by(futures_and_or_events, default_executor).event end |
.zip_futures(*futures_and_or_events) ⇒ Future Also known as: zip
Shortcut of #zip_futures_on with default :io
executor supplied.
238 239 240 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 238 def zip_futures(*futures_and_or_events) zip_futures_on default_executor, *futures_and_or_events end |
.zip_futures_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after all futures_and_or_events are resolved.
Its value is array of zipped future values. Its reason is array of reasons for rejection.
If there is an error it rejects.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
252 253 254 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 252 def zip_futures_on(default_executor, *futures_and_or_events) ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future end |
.zip_futures_over(enumerable, &future_factory) ⇒ Future
Edge Features are under active development and may change frequently.
- Deprecations are not added before incompatible changes.
- Edge version: major is always 0, minor bump means incompatible change, patch bump means compatible change.
- Edge features may also lack tests and documentation.
- Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Shortcut of #zip_futures_over_on with default :io
executor supplied.
72 73 74 |
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 72 def zip_futures_over(enumerable, &future_factory) zip_futures_over_on default_executor, enumerable, &future_factory end |
.zip_futures_over_on(default_executor, enumerable) {|element| ... } ⇒ Future
Edge Features are under active development and may change frequently.
- Deprecations are not added before incompatible changes.
- Edge version: major is always 0, minor bump means incompatible change, patch bump means compatible change.
- Edge features may also lack tests and documentation.
- Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Creates new future which is resolved after all the futures created by future_factory from
enumerable elements are resolved. Simplified it does:
zip(*enumerable.map { |e| future e, &future_factory })
90 91 92 93 |
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 90 def zip_futures_over_on(default_executor, enumerable, &future_factory) # ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future zip_futures_on(default_executor, *enumerable.map { |e| future e, &future_factory }) end |
.default_executor ⇒ Executor, :io, :fast Originally defined in module Configuration
Returns the executor which is used when none is supplied
to a factory method. The method can be overridden in the receivers of
include FactoryMethod
.
Instance Method Details
#any_event(*futures_and_or_events) ⇒ Future
Shortcut of #any_event_on with default :io
executor supplied.
317 318 319 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 317 def any_event(*futures_and_or_events) any_event_on default_executor, *futures_and_or_events end |
#any_event_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which becomes resolved after first of the futures_and_or_events resolves. If resolved it does not propagate AbstractEventFuture#touch, leaving delayed futures un-executed if they are not required any more.
327 328 329 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 327 def any_event_on(default_executor, *futures_and_or_events) AnyResolvedEventPromise.new_blocked_by(futures_and_or_events, default_executor).event end |
#any_fulfilled_future(*futures_and_or_events) ⇒ Future
Shortcut of #any_fulfilled_future_on with default :io
executor supplied.
298 299 300 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 298 def any_fulfilled_future(*futures_and_or_events) any_fulfilled_future_on default_executor, *futures_and_or_events end |
#any_fulfilled_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first of futures_and_or_events is fulfilled.
Its result equals result of the first resolved future or if all futures_and_or_events reject,
it has reason of the last resolved future.
If resolved it does not propagate AbstractEventFuture#touch, leaving delayed
futures un-executed if they are not required any more.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
311 312 313 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 311 def any_fulfilled_future_on(default_executor, *futures_and_or_events) AnyFulfilledFuturePromise.new_blocked_by(futures_and_or_events, default_executor).future end |
#any_resolved_future(*futures_and_or_events) ⇒ Future Also known as: any
Shortcut of #any_resolved_future_on with default :io
executor supplied.
276 277 278 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 276 def any_resolved_future(*futures_and_or_events) any_resolved_future_on default_executor, *futures_and_or_events end |
#any_resolved_future_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after first futures_and_or_events is resolved.
Its result equals result of the first resolved future.
If resolved it does not propagate AbstractEventFuture#touch, leaving delayed
futures un-executed if they are not required any more.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
292 293 294 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 292 def any_resolved_future_on(default_executor, *futures_and_or_events) AnyResolvedFuturePromise.new_blocked_by(futures_and_or_events, default_executor).future end |
#delay(*args, &task) ⇒ Future, Event
Shortcut of #delay_on with default :io
executor supplied.
188 189 190 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 188 def delay(*args, &task) delay_on default_executor, *args, &task end |
#delay_on(default_executor, *args) {|*args| ... } ⇒ Future #delay_on(default_executor) ⇒ Event
Creates new event or future which is resolved only after it is touched, see AbstractEventFuture#touch.
205 206 207 208 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 205 def delay_on(default_executor, *args, &task) event = DelayPromise.new(default_executor).event task ? event.chain(*args, &task) : event end |
#fulfilled_future(value, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be fulfilled with the given value.
125 126 127 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 125 def fulfilled_future(value, default_executor = self.default_executor) resolved_future true, value, nil, default_executor end |
#future(*args, &task) ⇒ Future
Shortcut of #future_on with default :io
executor supplied.
92 93 94 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 92 def future(*args, &task) future_on(default_executor, *args, &task) end |
#future_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor. Evaluation begins immediately.
104 105 106 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 104 def future_on(default_executor, *args, &task) ImmediateEventPromise.new(default_executor).future.then(*args, &task) end |
#make_future(nil, default_executor = self.default_executor) ⇒ Event #make_future(a_future, default_executor = self.default_executor) ⇒ Future #make_future(an_event, default_executor = self.default_executor) ⇒ Event #make_future(exception, default_executor = self.default_executor) ⇒ Future #make_future(value, default_executor = self.default_executor) ⇒ Future
General constructor. Behaves differently based on the argument's type. It's provided for convenience but it's better to be explicit.
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 172 def make_future(argument = nil, default_executor = self.default_executor) case argument when AbstractEventFuture # returning wrapper would change nothing argument when Exception rejected_future argument, default_executor when nil resolved_event default_executor else fulfilled_future argument, default_executor end end |
#rejected_future(reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be rejected with the given reason.
134 135 136 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 134 def rejected_future(reason, default_executor = self.default_executor) resolved_future false, nil, reason, default_executor end |
#resolvable_event ⇒ ResolvableEvent
Shortcut of #resolvable_event_on with default :io
executor supplied.
61 62 63 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 61 def resolvable_event resolvable_event_on default_executor end |
#resolvable_event_on(default_executor = self.default_executor) ⇒ ResolvableEvent
Created resolvable event, user is responsible for resolving the event once by ResolvableEvent#resolve.
70 71 72 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 70 def resolvable_event_on(default_executor = self.default_executor) ResolvableEventPromise.new(default_executor).future end |
#resolvable_future ⇒ ResolvableFuture
Shortcut of #resolvable_future_on with default :io
executor supplied.
76 77 78 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 76 def resolvable_future resolvable_future_on default_executor end |
#resolvable_future_on(default_executor = self.default_executor) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject
86 87 88 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 86 def resolvable_future_on(default_executor = self.default_executor) ResolvableFuturePromise.new(default_executor).future end |
#resolved_event(default_executor = self.default_executor) ⇒ Event
Creates resolved event.
142 143 144 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 142 def resolved_event(default_executor = self.default_executor) ImmediateEventPromise.new(default_executor).event end |
#resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ⇒ Future
Creates resolved future with will be either fulfilled with the given value or rejection with the given reason.
116 117 118 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 116 def resolved_future(fulfilled, value, reason, default_executor = self.default_executor) ImmediateFuturePromise.new(default_executor, fulfilled, value, reason).future end |
#schedule(intended_time, *args, &task) ⇒ Future, Event
Shortcut of #schedule_on with default :io
executor supplied.
212 213 214 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 212 def schedule(intended_time, *args, &task) schedule_on default_executor, intended_time, *args, &task end |
#schedule_on(default_executor, intended_time, *args) {|*args| ... } ⇒ Future #schedule_on(default_executor, intended_time) ⇒ Event
Creates new event or future which is resolved in intended_time.
231 232 233 234 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 231 def schedule_on(default_executor, intended_time, *args, &task) event = ScheduledPromise.new(default_executor, intended_time).event task ? event.chain(*args, &task) : event end |
#zip_events(*futures_and_or_events) ⇒ Event
Shortcut of #zip_events_on with default :io
executor supplied.
260 261 262 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 260 def zip_events(*futures_and_or_events) zip_events_on default_executor, *futures_and_or_events end |
#zip_events_on(default_executor, *futures_and_or_events) ⇒ Event
Creates new event which is resolved after all futures_and_or_events are resolved. (Future is resolved when fulfilled or rejected.)
270 271 272 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 270 def zip_events_on(default_executor, *futures_and_or_events) ZipEventsPromise.new_blocked_by(futures_and_or_events, default_executor).event end |
#zip_futures(*futures_and_or_events) ⇒ Future Also known as: zip
Shortcut of #zip_futures_on with default :io
executor supplied.
238 239 240 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 238 def zip_futures(*futures_and_or_events) zip_futures_on default_executor, *futures_and_or_events end |
#zip_futures_on(default_executor, *futures_and_or_events) ⇒ Future
Creates new future which is resolved after all futures_and_or_events are resolved.
Its value is array of zipped future values. Its reason is array of reasons for rejection.
If there is an error it rejects.
If event is supplied, which does not have value and can be only resolved, it's
represented as :fulfilled
with value nil
.
252 253 254 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 252 def zip_futures_on(default_executor, *futures_and_or_events) ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future end |
#zip_futures_over(enumerable, &future_factory) ⇒ Future
Edge Features are under active development and may change frequently.
- Deprecations are not added before incompatible changes.
- Edge version: major is always 0, minor bump means incompatible change, patch bump means compatible change.
- Edge features may also lack tests and documentation.
- Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Shortcut of #zip_futures_over_on with default :io
executor supplied.
72 73 74 |
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 72 def zip_futures_over(enumerable, &future_factory) zip_futures_over_on default_executor, enumerable, &future_factory end |
#zip_futures_over_on(default_executor, enumerable) {|element| ... } ⇒ Future
Edge Features are under active development and may change frequently.
- Deprecations are not added before incompatible changes.
- Edge version: major is always 0, minor bump means incompatible change, patch bump means compatible change.
- Edge features may also lack tests and documentation.
- Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Creates new future which is resolved after all the futures created by future_factory from
enumerable elements are resolved. Simplified it does:
zip(*enumerable.map { |e| future e, &future_factory })
90 91 92 93 |
# File 'lib/concurrent-ruby-edge/concurrent/edge/promises.rb', line 90 def zip_futures_over_on(default_executor, enumerable, &future_factory) # ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future zip_futures_on(default_executor, *enumerable.map { |e| future e, &future_factory }) end |
#default_executor ⇒ Executor, :io, :fast Originally defined in module Configuration
Returns the executor which is used when none is supplied
to a factory method. The method can be overridden in the receivers of
include FactoryMethod
.