Skip to content

Commit

Permalink
chore: update to revolt 0.2
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Jan 14, 2022
1 parent e9ae21d commit 1f94455
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 55 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-mbstring": "*",
"ext-sodium": "*",
"ext-intl": "*",
"revolt/event-loop": "~0.1.1"
"revolt/event-loop": "~0.2.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.6.1",
Expand Down
56 changes: 26 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Psl/Async/Awaitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function always(Closure $always): Awaitable
*/
public function await(): mixed
{
$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();

$this->state->subscribe(
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Async/Internal/AwaitableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function consume(): ?array
return $this->complete->await();
}

$this->queue->suspension = Psl\Async\Scheduler::createSuspension();
$this->queue->suspension = Psl\Async\Scheduler::getSuspension();

/** @var null|array{0: Tk, 1: Awaitable<Tv>} */
return $this->queue->suspension->suspend();
Expand Down
3 changes: 1 addition & 2 deletions src/Psl/Async/Internal/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ final class State
public function __destruct()
{
if ($this->exception && !$this->handled) {
$exception = Exception\UnhandledAwaitableException::forException($this->exception);
Scheduler::queue(static fn () => throw $exception);
throw Exception\UnhandledAwaitableException::forException($this->exception);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Async/KeyedSemaphore.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function waitFor(string|int $key, mixed $input): mixed
{
$this->ingoing[$key] = $this->ingoing[$key] ?? 0;
if ($this->ingoing[$key] === $this->concurrencyLimit) {
$this->pending[$key][] = $suspension = Scheduler::createSuspension();
$this->pending[$key][] = $suspension = Scheduler::getSuspension();

$suspension->suspend();
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public function waitForPending(string|int $key): void
return;
}

$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();
$this->waits[$key][] = $suspension;
$suspension->suspend();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Async/KeyedSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
public function waitFor(string|int $key, mixed $input): mixed
{
if (array_key_exists($key, $this->ingoing)) {
$this->pending[$key][] = $suspension = Scheduler::createSuspension();
$this->pending[$key][] = $suspension = Scheduler::getSuspension();

$suspension->suspend();
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public function waitForPending(string|int $key): void
return;
}

$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();
$this->waits[$key][] = $suspension;
$suspension->suspend();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Psl/Async/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ private function __construct()
/**
* Create an object used to suspend and resume execution, either within a fiber or from {main}.
*
* @see EventLoop::createSuspension()
* @see EventLoop::getSuspension()
*/
public static function createSuspension(): Suspension
public static function getSuspension(): Suspension
{
return EventLoop::createSuspension();
return EventLoop::getSuspension();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Async/Semaphore.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
public function waitFor(mixed $input): mixed
{
if ($this->ingoing === $this->concurrencyLimit) {
$this->pending[] = $suspension = Scheduler::createSuspension();
$this->pending[] = $suspension = Scheduler::getSuspension();

$suspension->suspend();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public function waitForPending(): void
return;
}

$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();
$this->waits[] = $suspension;
$suspension->suspend();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Async/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
public function waitFor(mixed $input): mixed
{
if ($this->ingoing) {
$this->pending[] = $suspension = Scheduler::createSuspension();
$this->pending[] = $suspension = Scheduler::getSuspension();

$suspension->suspend();
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function waitForPending(): void
return;
}

$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();
$this->waits[] = $suspension;
$suspension->suspend();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Async/later.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
function later(): void
{
$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();

Scheduler::defer(static fn () => $suspension->resume());

Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Async/sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
function sleep(float $seconds): void
{
$suspension = Scheduler::createSuspension();
$suspension = Scheduler::getSuspension();
$watcher = Scheduler::delay($seconds, static fn () => $suspension->resume(null));

try {
Expand Down
8 changes: 4 additions & 4 deletions src/Psl/IO/Internal/ResourceHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function write(string $bytes, ?float $timeout = null): int
{
// there's a pending read operation, wait for it.
if ($this->writing) {
$suspension = Async\Scheduler::createSuspension();
$suspension = Async\Scheduler::getSuspension();
$this->writeQueue[] = $suspension;
$suspension->suspend();
}
Expand All @@ -147,7 +147,7 @@ public function write(string $bytes, ?float $timeout = null): int
return $written;
}

$this->writeSuspension = Async\Scheduler::createSuspension();
$this->writeSuspension = Async\Scheduler::getSuspension();
/** @psalm-suppress MissingThrowsDocblock */
Async\Scheduler::enable($this->writeWatcher);
if (null !== $timeout) {
Expand Down Expand Up @@ -243,7 +243,7 @@ public function read(?int $max_bytes = null, ?float $timeout = null): string
{
// there's a pending read operation, wait for it.
if ($this->reading) {
$suspension = Async\Scheduler::createSuspension();
$suspension = Async\Scheduler::getSuspension();
$this->readQueue[] = $suspension;
$suspension->suspend();
}
Expand All @@ -258,7 +258,7 @@ public function read(?int $max_bytes = null, ?float $timeout = null): string
return $chunk;
}

$this->readSuspension = Async\Scheduler::createSuspension();
$this->readSuspension = Async\Scheduler::getSuspension();
/** @psalm-suppress MissingThrowsDocblock */
Async\Scheduler::enable($this->readWatcher);
if (null !== $timeout) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Network/Internal/AbstractStreamServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public function nextConnection(): Network\StreamSocketInterface
}

if (null !== $this->suspension) {
$suspension = Async\Scheduler::createSuspension();
$suspension = Async\Scheduler::getSuspension();
$this->queue[] = $suspension;
$suspension->suspend();
} else {
/** @psalm-suppress MissingThrowsDocblock */
Async\Scheduler::enable($this->watcher);
}

$this->suspension = Async\Scheduler::createSuspension();
$this->suspension = Async\Scheduler::getSuspension();

try {
/** @var resource $stream */
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Network/Internal/socket_connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function socket_connect(string $uri, array $context = [], ?float $timeout = null
throw new Exception\RuntimeException('Failed to connect to client "' . $uri . '".', $errno);
}

$suspension = Async\Scheduler::createSuspension();
$suspension = Async\Scheduler::getSuspension();

$write_watcher = '';
$timeout_watcher = '';
Expand Down

0 comments on commit 1f94455

Please sign in to comment.