Class: ConcurrentRails::Promises
- Inherits:
-
Object
- Object
- ConcurrentRails::Promises
- Defined in:
- lib/concurrent_rails/promises.rb
Instance Attribute Summary collapse
-
#executor ⇒ Object
readonly
Returns the value of attribute executor.
Class Method Summary collapse
- .any_resolved_future(*promises) ⇒ Object
- .fulfilled_future(value, executor = :io) ⇒ Object
- .rejected_future(reason, executor = :io) ⇒ Object
- .wrap_task(task) ⇒ Object
- .zip(*promises) ⇒ Object
Instance Method Summary collapse
-
#initialize(executor, instance) ⇒ Promises
constructor
A new instance of Promises.
- #touch ⇒ Object
- #wait(timeout = nil) ⇒ Object
Constructor Details
#initialize(executor, instance) ⇒ Promises
Returns a new instance of Promises.
43 44 45 46 |
# File 'lib/concurrent_rails/promises.rb', line 43 def initialize(executor, instance) @executor = executor @instance = instance end |
Instance Attribute Details
#executor ⇒ Object (readonly)
Returns the value of attribute executor.
88 89 90 |
# File 'lib/concurrent_rails/promises.rb', line 88 def executor @executor end |
Class Method Details
.any_resolved_future(*promises) ⇒ Object
20 21 22 |
# File 'lib/concurrent_rails/promises.rb', line 20 def any_resolved_future(*promises) new(:io, Concurrent::Promises.any_resolved_future(*unwrap(promises))) end |
.fulfilled_future(value, executor = :io) ⇒ Object
24 25 26 |
# File 'lib/concurrent_rails/promises.rb', line 24 def fulfilled_future(value, executor = :io) new(executor, Concurrent::Promises.fulfilled_future(value)) end |
.rejected_future(reason, executor = :io) ⇒ Object
28 29 30 |
# File 'lib/concurrent_rails/promises.rb', line 28 def rejected_future(reason, executor = :io) new(executor, Concurrent::Promises.rejected_future(reason)) end |
.wrap_task(task) ⇒ Object
32 33 34 |
# File 'lib/concurrent_rails/promises.rb', line 32 def wrap_task(task) proc { |*args| Rails.application.executor.wrap { task.call(*args) } } end |
.zip(*promises) ⇒ Object
16 17 18 |
# File 'lib/concurrent_rails/promises.rb', line 16 def zip(*promises) new(:io, Concurrent::Promises.zip(*unwrap(promises))) end |
Instance Method Details
#touch ⇒ Object
60 61 62 63 64 |
# File 'lib/concurrent_rails/promises.rb', line 60 def touch instance.touch self end |
#wait(timeout = nil) ⇒ Object
66 67 68 69 70 |
# File 'lib/concurrent_rails/promises.rb', line 66 def wait(timeout = nil) result = rails_wrapped { instance.wait(timeout) } timeout ? result : self end |