Class: ActiveRecord::FutureResult
- Inherits:
-
Object
- Object
- ActiveRecord::FutureResult
show all
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb
Overview
Defined Under Namespace
Classes: EventBuffer, SelectAll
Constant Summary
collapse
- Canceled =
Class.new(ActiveRecordError)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pool, *args, **kwargs) ⇒ FutureResult
Returns a new instance of FutureResult.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 33
def initialize(pool, *args, **kwargs)
@mutex = Mutex.new
@session = nil
@pool = pool
@args = args
@kwargs = kwargs
@pending = true
@error = nil
@result = nil
@instrumenter = ActiveSupport::Notifications.instrumenter
@event_buffer = nil
end
|
Instance Attribute Details
#lock_wait ⇒ Object
Returns the value of attribute lock_wait.
31
32
33
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 31
def lock_wait
@lock_wait
end
|
Instance Method Details
57
58
59
60
61
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 57
def cancel
@pending = false
@error = Canceled
self
end
|
#execute!(connection) ⇒ Object
53
54
55
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 53
def execute!(connection)
execute_query(connection)
end
|
#execute_or_skip ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 63
def execute_or_skip
return unless pending?
@pool.with_connection do |connection|
return unless @mutex.try_lock
begin
if pending?
@event_buffer = EventBuffer.new(self, @instrumenter)
connection.with_instrumenter(@event_buffer) do
execute_query(connection, async: true)
end
end
ensure
@mutex.unlock
end
end
end
|
#pending? ⇒ Boolean
94
95
96
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 94
def pending?
@pending && (!@session || @session.active?)
end
|
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 81
def result
execute_or_wait
@event_buffer&.flush
if canceled?
raise Canceled
elsif @error
raise @error
else
@result
end
end
|
#schedule!(session) ⇒ Object
48
49
50
51
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/future_result.rb', line 48
def schedule!(session)
@session = session
@pool.schedule_query(self)
end
|