Skip to content

Commit

Permalink
Update for Stream onDisposal() and onCompletion()
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Aug 1, 2020
1 parent 696ced1 commit 23b8c49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/CommandResult.php
Expand Up @@ -2,8 +2,7 @@

namespace Amp\Sql\Common;

use Amp\DisposedException;
use Amp\Failure;
use Amp\Loop;
use Amp\Promise;
use Amp\Sql\Result;
use Amp\Success;
Expand Down Expand Up @@ -33,7 +32,23 @@ public function continue(): Promise

public function dispose(): void
{
$this->promise = new Failure(new DisposedException);
// No-op
}

public function onDisposal(callable $onDisposal): void
{
// No-op, result is complete on creation
}

public function onCompletion(callable $onCompletion): void
{
try {
$onCompletion(null);
} catch (\Throwable $e) {
Loop::defer(static function () use ($e): void {
throw $e;
});
}
}

public function getNextResult(): Promise
Expand Down
10 changes: 10 additions & 0 deletions src/PooledResult.php
Expand Up @@ -72,6 +72,16 @@ public function dispose(): void
}
}

public function onDisposal(callable $onDisposal): void
{
$this->result->onDisposal($onDisposal);
}

public function onCompletion(callable $onCompletion): void
{
$this->result->onCompletion($onCompletion);
}

public function getRowCount(): ?int
{
return $this->result->getRowCount();
Expand Down

0 comments on commit 23b8c49

Please sign in to comment.