Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
853 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of `prooph/event-store-client`. | ||
* (c) 2018-2018 prooph software GmbH <contact@prooph.de> | ||
* (c) 2018-2018 Sascha-Oliver Prolic <saschaprolic@googlemail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prooph\EventStoreClient\Internal; | ||
|
||
use Amp\Deferred; | ||
use Amp\Promise; | ||
|
||
/** @internal */ | ||
class ManualResetEventSlim | ||
{ | ||
/** @var bool */ | ||
private $isSet; | ||
/** @var Deferred */ | ||
private $deferred; | ||
|
||
public function __construct(bool $isSet = false) | ||
{ | ||
$this->isSet = $isSet; | ||
$this->deferred = new Deferred(); | ||
|
||
if ($isSet) { | ||
$this->deferred->resolve(true); | ||
} | ||
} | ||
|
||
public function set(): void | ||
{ | ||
$this->isSet = true; | ||
$this->deferred->resolve(true); | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->isSet = false; | ||
$this->deferred = new Deferred(); | ||
} | ||
|
||
public function wait(int $timeout): Promise | ||
{ | ||
$promise = Promise\timeout($this->deferred->promise(), $timeout); | ||
|
||
$deferred = new Deferred(); | ||
$newPromise = $deferred->promise(); | ||
|
||
$promise->onResolve(function (?\Throwable $exception = null, $result) use ($deferred) { | ||
if ($exception) { | ||
$deferred->resolve(false); | ||
} else { | ||
$deferred->resolve(true); | ||
} | ||
}); | ||
|
||
return $newPromise; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of `prooph/event-store-client`. | ||
* (c) 2018-2018 prooph software GmbH <contact@prooph.de> | ||
* (c) 2018-2018 Sascha-Oliver Prolic <saschaprolic@googlemail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ProophTest\EventStoreClient; | ||
|
||
use Amp\Deferred; | ||
use Amp\Promise; | ||
use InvalidArgumentException; | ||
use Prooph\EventStoreClient\Exception\RuntimeException; | ||
|
||
/** @internal */ | ||
class CountdownEvent | ||
{ | ||
/** @var int */ | ||
private $counter; | ||
/** @var Deferred */ | ||
private $deferred; | ||
|
||
public function __construct(int $counter) | ||
{ | ||
if ($counter < 1) { | ||
throw new InvalidArgumentException('Counter must be positive'); | ||
} | ||
|
||
$this->counter = $counter; | ||
$this->deferred = new Deferred(); | ||
} | ||
|
||
public function signal(): void | ||
{ | ||
if (0 === $this->counter) { | ||
throw new RuntimeException('CountdownEvent already resolved'); | ||
} | ||
|
||
--$this->counter; | ||
|
||
if (0 === $this->counter) { | ||
$this->deferred->resolve(true); | ||
} | ||
} | ||
|
||
public function wait(int $timeout): Promise | ||
{ | ||
$promise = Promise\timeout($this->deferred->promise(), $timeout); | ||
|
||
$deferred = new Deferred(); | ||
$newPromise = $deferred->promise(); | ||
|
||
$promise->onResolve(function (?\Throwable $exception = null, $result) use ($deferred) { | ||
if ($exception) { | ||
$deferred->resolve(false); | ||
} else { | ||
$deferred->resolve(true); | ||
} | ||
}); | ||
|
||
return $newPromise; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.