Module: Concurrent::Promises::FactoryMethods
- Includes:
- NewChannelIntegration
- Included in:
- Concurrent::Promises
- Defined in:
- lib/concurrent/edge/promises.rb,
lib/concurrent/edge/old_channel_integration.rb,
lib/concurrent/edge/promises.rb
Overview
Defined Under Namespace
Modules: NewChannelIntegration
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.
-
#create(argument = nil, default_executor = :io) ⇒ Event, Future
General constructor.
-
#delay(*args, &task) ⇒ Future
Shortcut of #delay_on with default ‘:io` executor supplied.
-
#delay_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor.
-
#fulfilled_future(value, default_executor = :io) ⇒ 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.
-
#rejected_future(reason, default_executor = :io) ⇒ 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 = :io) ⇒ 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 = :io) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject.
-
#resolved_event(default_executor = :io) ⇒ Event
Creates resolved event.
-
#resolved_future(fulfilled, value, reason, default_executor = :io) ⇒ 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
Shortcut of #schedule_on with default ‘:io` executor supplied.
-
#schedule_on(default_executor, intended_time, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor.
-
#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.
Methods included from NewChannelIntegration
Instance Method Details
#any_event(*futures_and_or_events) ⇒ Future
Shortcut of #any_event_on with default ‘:io` executor supplied.
312 313 314 |
# File 'lib/concurrent/edge/promises.rb', line 312 def any_event(*futures_and_or_events) any_event_on :io, *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.
322 323 324 |
# File 'lib/concurrent/edge/promises.rb', line 322 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.
293 294 295 |
# File 'lib/concurrent/edge/promises.rb', line 293 def any_fulfilled_future(*futures_and_or_events) any_fulfilled_future_on :io, *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`.
306 307 308 |
# File 'lib/concurrent/edge/promises.rb', line 306 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.
271 272 273 |
# File 'lib/concurrent/edge/promises.rb', line 271 def any_resolved_future(*futures_and_or_events) any_resolved_future_on :io, *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`.
287 288 289 |
# File 'lib/concurrent/edge/promises.rb', line 287 def any_resolved_future_on(default_executor, *futures_and_or_events) AnyResolvedFuturePromise.new_blocked_by(futures_and_or_events, default_executor).future end |
#create(nil, default_executor = :io) ⇒ Event #create(a_future, default_executor = :io) ⇒ Future #create(an_event, default_executor = :io) ⇒ Event #create(exception, default_executor = :io) ⇒ Future #create(value, default_executor = :io) ⇒ Future
General constructor. Behaves differently based on the argument’s type. It’s provided for convenience but it’s better to be explicit.
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/concurrent/edge/promises.rb', line 186 def create(argument = nil, default_executor = :io) 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 |
#delay(*args, &task) ⇒ Future
Shortcut of #delay_on with default ‘:io` executor supplied.
202 203 204 |
# File 'lib/concurrent/edge/promises.rb', line 202 def delay(*args, &task) delay_on :io, *args, &task end |
#delay_on(default_executor, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor. The task will be evaluated only after the future is touched, see AbstractEventFuture#touch
210 211 212 |
# File 'lib/concurrent/edge/promises.rb', line 210 def delay_on(default_executor, *args, &task) DelayPromise.new(default_executor).event.chain(*args, &task) end |
#fulfilled_future(value, default_executor = :io) ⇒ Future
Creates resolved future with will be fulfilled with the given value.
140 141 142 |
# File 'lib/concurrent/edge/promises.rb', line 140 def fulfilled_future(value, default_executor = :io) resolved_future true, value, nil, default_executor end |
#future(*args, &task) ⇒ Future
Shortcut of #future_on with default ‘:io` executor supplied.
109 110 111 |
# File 'lib/concurrent/edge/promises.rb', line 109 def future(*args, &task) future_on(:io, *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.
123 124 125 |
# File 'lib/concurrent/edge/promises.rb', line 123 def future_on(default_executor, *args, &task) ImmediateEventPromise.new(default_executor).future.then(*args, &task) end |
#rejected_future(reason, default_executor = :io) ⇒ Future
Creates resolved future with will be rejected with the given reason.
148 149 150 |
# File 'lib/concurrent/edge/promises.rb', line 148 def rejected_future(reason, default_executor = :io) resolved_future false, nil, reason, default_executor end |
#resolvable_event ⇒ ResolvableEvent
Shortcut of #resolvable_event_on with default ‘:io` executor supplied.
78 79 80 |
# File 'lib/concurrent/edge/promises.rb', line 78 def resolvable_event resolvable_event_on :io end |
#resolvable_event_on(default_executor = :io) ⇒ ResolvableEvent
Created resolvable event, user is responsible for resolving the event once by ResolvableEvent#resolve.
87 88 89 |
# File 'lib/concurrent/edge/promises.rb', line 87 def resolvable_event_on(default_executor = :io) ResolvableEventPromise.new(default_executor).future end |
#resolvable_future ⇒ ResolvableFuture
Shortcut of #resolvable_future_on with default ‘:io` executor supplied.
93 94 95 |
# File 'lib/concurrent/edge/promises.rb', line 93 def resolvable_future resolvable_future_on :io end |
#resolvable_future_on(default_executor = :io) ⇒ ResolvableFuture
Creates resolvable future, user is responsible for resolving the future once by ResolvableFuture#resolve, ResolvableFuture#fulfill, or ResolvableFuture#reject
103 104 105 |
# File 'lib/concurrent/edge/promises.rb', line 103 def resolvable_future_on(default_executor = :io) ResolvableFuturePromise.new(default_executor).future end |
#resolved_event(default_executor = :io) ⇒ Event
Creates resolved event.
156 157 158 |
# File 'lib/concurrent/edge/promises.rb', line 156 def resolved_event(default_executor = :io) ImmediateEventPromise.new(default_executor).event end |
#resolved_future(fulfilled, value, reason, default_executor = :io) ⇒ Future
Creates resolved future with will be either fulfilled with the given value or rejection with the given reason.
132 133 134 |
# File 'lib/concurrent/edge/promises.rb', line 132 def resolved_future(fulfilled, value, reason, default_executor = :io) ImmediateFuturePromise.new(default_executor, fulfilled, value, reason).future end |
#schedule(intended_time, *args, &task) ⇒ Future
Shortcut of #schedule_on with default ‘:io` executor supplied.
216 217 218 |
# File 'lib/concurrent/edge/promises.rb', line 216 def schedule(intended_time, *args, &task) schedule_on :io, intended_time, *args, &task end |
#schedule_on(default_executor, intended_time, *args) {|*args| ... } ⇒ Future
Constructs new Future which will be resolved after block is evaluated on default executor. The task is planned for execution in intended_time.
227 228 229 |
# File 'lib/concurrent/edge/promises.rb', line 227 def schedule_on(default_executor, intended_time, *args, &task) ScheduledPromise.new(default_executor, intended_time).event.chain(*args, &task) end |
#zip_events(*futures_and_or_events) ⇒ Event
Shortcut of #zip_events_on with default ‘:io` executor supplied.
255 256 257 |
# File 'lib/concurrent/edge/promises.rb', line 255 def zip_events(*futures_and_or_events) zip_events_on :io, *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.)
265 266 267 |
# File 'lib/concurrent/edge/promises.rb', line 265 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.
233 234 235 |
# File 'lib/concurrent/edge/promises.rb', line 233 def zip_futures(*futures_and_or_events) zip_futures_on :io, *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`.
247 248 249 |
# File 'lib/concurrent/edge/promises.rb', line 247 def zip_futures_on(default_executor, *futures_and_or_events) ZipFuturesPromise.new_blocked_by(futures_and_or_events, default_executor).future end |