Skip to content

Commit

Permalink
Merge pull request #1 from brnck/master
Browse files Browse the repository at this point in the history
Change Lock to LockInterface
  • Loading branch information
vbartusevicius authored Dec 3, 2018
2 parents 59c9aab + 0665b15 commit 6f2235a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.0
### Changed
- `LockManager` now takes and return `LockInterface` instead of `Lock` which implements it

## 0.1.1
### Changed
- Downgraded `phpunit` to `^6.0` to have PHP7.0 dev compatibility
Expand Down
10 changes: 5 additions & 5 deletions src/Service/LockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Lock\Exception\LockAcquiringException;
use Symfony\Component\Lock\Factory;
use Symfony\Component\Lock\Lock;
use Symfony\Component\Lock\LockInterface;

class LockManager
{
Expand All @@ -19,12 +19,12 @@ public function __construct(
$this->ttl = $ttl;
}

public function createLock(string $resource): Lock
public function createLock(string $resource): LockInterface
{
return $this->lockFactory->createLock($resource, $this->ttl);
}

public function acquire(Lock $lock): bool
public function acquire(LockInterface $lock): bool
{
foreach (range(1, $this->ttl) as $waited) {
if ($lock->acquire()) {
Expand All @@ -41,15 +41,15 @@ public function acquire(Lock $lock): bool
throw new LockAcquiringException('Failed to acquire lock');
}

public function createAcquired(string $resource): Lock
public function createAcquired(string $resource): LockInterface
{
$lock = $this->createLock($resource);
$this->acquire($lock);

return $lock;
}

public function release(Lock $lock)
public function release(LockInterface $lock)
{
$lock->release();
}
Expand Down

0 comments on commit 6f2235a

Please sign in to comment.