Class: ActiveRecord::AsynchronousQueriesTracker::Session
- Inherits:
-
Object
- Object
- ActiveRecord::AsynchronousQueriesTracker::Session
- Defined in:
- lib/active_record/asynchronous_queries_tracker.rb
Overview
:nodoc:
Instance Method Summary collapse
- #active? ⇒ Boolean
- #finalize(wait = false) ⇒ Object
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #synchronize(&block) ⇒ Object
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
9 10 11 12 |
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 9 def initialize @active = Concurrent::AtomicBoolean.new(true) @lock = Concurrent::ReadWriteLock.new end |
Instance Method Details
#active? ⇒ Boolean
14 15 16 |
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 14 def active? @active.true? end |
#finalize(wait = false) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 22 def finalize(wait = false) @active.make_false if wait # Wait until all thread with a read lock are done @lock.with_write_lock { } end end |
#synchronize(&block) ⇒ Object
18 19 20 |
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 18 def synchronize(&block) @lock.with_read_lock(&block) end |