Class: Concurrent::Promises::AbstractEventFuture
- Inherits:
-
Synchronization::Object
- Object
- Synchronization::Object
- Concurrent::Promises::AbstractEventFuture
- Includes:
- ThrottleIntegration
- Defined in:
- lib/concurrent/edge/promises.rb,
lib/concurrent/edge/throttle.rb
Overview
Defined Under Namespace
Modules: ThrottleIntegration
Instance Method Summary collapse
-
#add_callback_notify_blocked(promise, index) ⇒ Object
# @!visibility private.
-
#chain(*args, &task) ⇒ Future
Shortcut of #chain_on with default ‘:io` executor supplied.
-
#chain_on(executor, *args, &task) ⇒ Future
Chains the task to be executed asynchronously on executor after it is resolved.
-
#chain_resolvable(resolvable) ⇒ self
(also: #tangle)
Resolves the resolvable when receiver is resolved.
-
#default_executor ⇒ Executor
Returns default executor.
-
#on_resolution(*args, &callback) ⇒ self
Shortcut of #on_resolution_using with default ‘:io` executor supplied.
-
#on_resolution!(*args, &callback) ⇒ self
Stores the callback to be executed synchronously on resolving thread after it is resolved.
-
#on_resolution_using(executor, *args, &callback) ⇒ self
Stores the callback to be executed asynchronously on executor after it is resolved.
-
#pending?(state = internal_state) ⇒ Boolean
Is it in pending state?.
-
#resolved?(state = internal_state) ⇒ Boolean
Is it in resolved state?.
-
#state ⇒ Symbol
Returns its state.
-
#to_s ⇒ String
(also: #inspect)
Short string representation.
-
#touch ⇒ self
Propagates touch.
-
#wait(timeout = nil) ⇒ Future, ...
Wait (block the Thread) until receiver is #resolved?.
-
#with_default_executor(executor) ⇒ AbstractEventFuture
abstract
Crates new object with same class with the executor set as its new default executor.
Methods included from ThrottleIntegration
#chain_throttled_by, #throttled_by
Instance Method Details
#add_callback_notify_blocked(promise, index) ⇒ Object
# @!visibility private
742 743 744 |
# File 'lib/concurrent/edge/promises.rb', line 742 def add_callback_notify_blocked(promise, index) add_callback :callback_notify_blocked, promise, index end |
#chain(*args, &task) ⇒ Future
Shortcut of #chain_on with default ‘:io` executor supplied.
605 606 607 |
# File 'lib/concurrent/edge/promises.rb', line 605 def chain(*args, &task) chain_on @DefaultExecutor, *args, &task end |
#an_event.chain_on(executor, *args) {|*args| ... } ⇒ Future #a_future.chain_on(executor, *args) {|fulfilled, value, reason, *args| ... } ⇒ Future
Chains the task to be executed asynchronously on executor after it is resolved.
623 624 625 |
# File 'lib/concurrent/edge/promises.rb', line 623 def chain_on(executor, *args, &task) ChainPromise.new_blocked_by1(self, @DefaultExecutor, executor, args, &task).future end |
#chain_resolvable(resolvable) ⇒ self Also known as: tangle
Resolves the resolvable when receiver is resolved.
638 639 640 |
# File 'lib/concurrent/edge/promises.rb', line 638 def chain_resolvable(resolvable) on_resolution! { resolvable.resolve_with internal_state } end |
#default_executor ⇒ Executor
Returns default executor.
599 600 601 |
# File 'lib/concurrent/edge/promises.rb', line 599 def default_executor @DefaultExecutor end |
#on_resolution(*args, &callback) ⇒ self
Shortcut of #on_resolution_using with default ‘:io` executor supplied.
646 647 648 |
# File 'lib/concurrent/edge/promises.rb', line 646 def on_resolution(*args, &callback) on_resolution_using @DefaultExecutor, *args, &callback end |
#an_event.on_resolution!(*args) {|*args| ... } ⇒ self #a_future.on_resolution!(*args) {|fulfilled, value, reason, *args| ... } ⇒ self
Stores the callback to be executed synchronously on resolving thread after it is resolved.
664 665 666 |
# File 'lib/concurrent/edge/promises.rb', line 664 def on_resolution!(*args, &callback) add_callback :callback_on_resolution, args, callback end |
#an_event.on_resolution_using(executor, *args) {|*args| ... } ⇒ self #a_future.on_resolution_using(executor, *args) {|fulfilled, value, reason, *args| ... } ⇒ self
Stores the callback to be executed asynchronously on executor after it is resolved.
682 683 684 |
# File 'lib/concurrent/edge/promises.rb', line 682 def on_resolution_using(executor, *args, &callback) add_callback :async_callback_on_resolution, executor, args, callback end |
#pending?(state = internal_state) ⇒ Boolean
Is it in pending state?
558 559 560 |
# File 'lib/concurrent/edge/promises.rb', line 558 def pending?(state = internal_state) !state.resolved? end |
#resolved?(state = internal_state) ⇒ Boolean
Is it in resolved state?
564 565 566 |
# File 'lib/concurrent/edge/promises.rb', line 564 def resolved?(state = internal_state) state.resolved? end |
#an_event.state ⇒ :pending, :resolved #a_future.state ⇒ :pending, ...
Returns its state.
552 553 554 |
# File 'lib/concurrent/edge/promises.rb', line 552 def state internal_state.to_sym end |
#to_s ⇒ String Also known as: inspect
Returns Short string representation.
628 629 630 |
# File 'lib/concurrent/edge/promises.rb', line 628 def to_s format '<#%s:0x%x %s>', self.class, object_id << 1, state end |
#touch ⇒ self
Propagates touch. Requests all the delayed futures, which it depends on, to be executed. This method is called by any other method requiring resolved state, like #wait.
571 572 573 574 |
# File 'lib/concurrent/edge/promises.rb', line 571 def touch @Promise.touch self end |
#wait(timeout = nil) ⇒ Future, ...
This function potentially blocks current thread until the Future is resolved. Be careful it can deadlock. Try to chain instead.
Wait (block the Thread) until receiver is #resolved?. Calls #touch.
587 588 589 590 |
# File 'lib/concurrent/edge/promises.rb', line 587 def wait(timeout = nil) result = wait_until_resolved(timeout) timeout ? result : self end |
#with_default_executor(executor) ⇒ AbstractEventFuture
Crates new object with same class with the executor set as its new default executor. Any futures depending on it will use the new default executor.
692 693 694 |
# File 'lib/concurrent/edge/promises.rb', line 692 def with_default_executor(executor) raise NotImplementedError end |