Skip to content

Commit b4d1cb7

Browse files
mbonneaudavidwdan
authored andcommitted
Create specific exception for timeout (#119)
* Create specific exception for `timeout` so a timeout can be identified downstream * Moved to Rx\Exception namespace and added base Exception
1 parent 16f9202 commit b4d1cb7

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

src/Exception/Exception.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Rx\Exception;
4+
5+
class Exception extends \Exception
6+
{
7+
}

src/Exception/TimeoutException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Rx\Exception;
4+
5+
class TimeoutException extends Exception
6+
{
7+
}

src/Observable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,9 @@ public function delay(int $delay, SchedulerInterface $scheduler = null): Observa
15521552
}
15531553

15541554
/**
1555+
* Errors the observable sequence if no item is emitted in the specified time.
1556+
* When a timeout occurs, this operator errors with an instance of Rx\Exception\TimeoutException
1557+
*
15551558
* @param $timeout
15561559
* @param ObservableInterface $timeoutObservable
15571560
* @param SchedulerInterface $scheduler

src/Operator/TimeoutOperator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Rx\Observer\CallbackObserver;
1111
use Rx\ObserverInterface;
1212
use Rx\SchedulerInterface;
13+
use Rx\Exception\TimeoutException;
1314

1415
final class TimeoutOperator implements OperatorInterface
1516
{
@@ -26,7 +27,7 @@ public function __construct(int $timeout, ObservableInterface $timeoutObservable
2627
$this->timeoutObservable = $timeoutObservable;
2728

2829
if ($this->timeoutObservable === null) {
29-
$this->timeoutObservable = new ErrorObservable(new \Exception('timeout'), $scheduler);
30+
$this->timeoutObservable = new ErrorObservable(new TimeoutException('timeout'), $scheduler);
3031
}
3132
}
3233

test/Rx/Functional/Operator/TimeoutTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Rx\Functional\FunctionalTestCase;
66
use Rx\Observable\ErrorObservable;
7+
use Rx\Exception\TimeoutException;
78

89
class TimeoutTest extends FunctionalTestCase
910
{
@@ -54,7 +55,7 @@ public function timeout_relative_time_timeout_occurs_with_default_error()
5455

5556
$this->assertMessages(
5657
[
57-
onError(401, new \Exception())
58+
onError(401, new TimeoutException())
5859
],
5960
$results->getMessages()
6061
);

0 commit comments

Comments
 (0)