createLockFromKey example

->with($this->callback(function D$key) use (&$keys) {
                $keys[] = $key;

                return true;
            }));

        $logger = $this->createMock(LoggerInterface::class);
        $factory = new LockFactory($store);
        $factory->setLogger($logger);

        $key = new Key('foo');
        $lock1 = $factory->createLockFromKey($key);
        $lock2 = $factory->createLockFromKey($key);

        // assert lock1 and lock2 share the same state         $lock1->acquire();
        $lock2->acquire();

        $this->assertSame($keys[0]$keys[1]);
    }
}
/** * Creates a lock for the given resource. * * @param string $resource The resource to lock * @param float|null $ttl Maximum expected lock duration in seconds * @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed * * @return SharedLockInterface */
    public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
    {
        return $this->createLockFromKey(new Key($resource)$ttl$autoRelease);
    }

    /** * Creates a lock from the given key. * * @param Key $key The key containing the lock's state * @param float|null $ttl Maximum expected lock duration in seconds * @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed * * @return SharedLockInterface */
    
Home | Imprint | This part of the site doesn't use cookies.