Class: Agent::Lock::Facade::Async
- Inherits:
-
Object
- Object
- Agent::Lock::Facade::Async
- Defined in:
- lib/agent/lock/facade/async.rb
Overview
locker.async: every lock method of a Agent::Lock::Facade, run off the calling
thread and answered with a Concurrent::Promises::Future.
A proxy of our own rather than Concurrent::Async, whose
method_missing forwards positional arguments only: there,
async.acquire("lib/**", agent_id: "other") folded the keywords
into intent, and the lock was taken, reported as acquired, and
signed by the facade's default holder in whatever checkout the
process happened to be in. Here keywords and blocks reach the facade
exactly as they would on a direct call.
One facade's calls run one at a time, in the order they were made.
Handing each call to the I/O pool on its own ran them in parallel:
an async.release could overtake the async.acquire issued before
it, and fifty async.note calls on one scope, each reading the
record, adding its note and writing it back, kept two notes while
every future reported :noted.
A future nobody waits on can be dropped when the process exits with
the pool still busy. Call value! or wait on every future whose
outcome matters, a release most of all.
Constant Summary collapse
- METHODS =
The facade methods offered asynchronously: the ones that touch a store.
version,skills_pathand the like answer at once. %i[acquire release check list mine release_all break_lock note resume whoami].freeze
Class Method Summary collapse
-
.load! ⇒ void
concurrent-ruby is not a dependency of this gem.
Instance Method Summary collapse
-
#initialize(facade) ⇒ Async
constructor
A new instance of Async.
Constructor Details
#initialize(facade) ⇒ Async
Returns a new instance of Async.
45 46 47 48 49 50 |
# File 'lib/agent/lock/facade/async.rb', line 45 def initialize(facade) @facade = facade @queue = Concurrent::SerializedExecutionDelegator.new(Concurrent.global_io_executor) @running = :"agent_lock_async_#{object_id}" freeze end |
Class Method Details
.load! ⇒ void
This method returns an undefined value.
concurrent-ruby is not a dependency of this gem. Only an async:
facade needs it, so only an async: facade asks for it.
37 38 39 40 41 42 |
# File 'lib/agent/lock/facade/async.rb', line 37 def self.load! require "concurrent" rescue LoadError => e raise LoadError, "Agent::Lock::Facade.new(async: true) needs the concurrent-ruby gem: " \ "add `gem \"concurrent-ruby\"` to your Gemfile (#{e.})" end |