Class: ActiveRecord::Futures::Future
- Inherits:
-
Object
- Object
- ActiveRecord::Futures::Future
- Defined in:
- lib/active_record/futures/future.rb
Instance Attribute Summary collapse
-
#binds ⇒ Object
readonly
Returns the value of attribute binds.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #execute(flush = true) ⇒ Object
- #executed? ⇒ Boolean
- #fulfill(result) ⇒ Object
- #fulfilled? ⇒ Boolean
-
#initialize(relation, query, binds, execution) ⇒ Future
constructor
A new instance of Future.
- #load ⇒ Object
Constructor Details
#initialize(relation, query, binds, execution) ⇒ Future
Returns a new instance of Future.
7 8 9 10 11 12 13 |
# File 'lib/active_record/futures/future.rb', line 7 def initialize(relation, query, binds, execution) @relation = relation @query = query @binds = binds @execution = execution FutureRegistry.register(self) end |
Instance Attribute Details
#binds ⇒ Object (readonly)
Returns the value of attribute binds.
4 5 6 |
# File 'lib/active_record/futures/future.rb', line 4 def binds @binds end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
4 5 6 |
# File 'lib/active_record/futures/future.rb', line 4 def query @query end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/active_record/futures/future.rb', line 4 def result @result end |
Instance Method Details
#execute(flush = true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_record/futures/future.rb', line 33 def execute(flush = true) # Flush all the futures upon first attempt to exec a future FutureRegistry.flush if flush && !executed? unless executed? @value = execution.call @executed = true end @value end |
#executed? ⇒ Boolean
45 46 47 |
# File 'lib/active_record/futures/future.rb', line 45 def executed? @executed end |
#fulfill(result) ⇒ Object
15 16 17 |
# File 'lib/active_record/futures/future.rb', line 15 def fulfill(result) @result = result end |
#fulfilled? ⇒ Boolean
19 20 21 |
# File 'lib/active_record/futures/future.rb', line 19 def fulfilled? !result.nil? end |
#load ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/futures/future.rb', line 23 def load # Only perform a load if the adapter supports futures. # This allows to fallback to normal query execution in futures # when the adapter does not support futures. return unless connection_supports_futures? FutureRegistry.current = self execute(false) FutureRegistry.current = nil end |