doAcquire()); } /** * Attempts to acquire the lock and sleeps for a time if the lock could not be acquired. * * @return \Generator */ public function doAcquire(): \Generator { $tsl = function () { return ($this->lock ? $this->lock = false : true); }; while (!$this->lock || $this->synchronized($tsl)) { yield new Delayed(self::LATENCY_TIMEOUT); } return new Lock(function () { $this->release(); }); } /** * Releases the lock. */ protected function release() { $this->lock = true; } }