aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2015-08-28 09:27:15 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2015-08-28 09:27:15 +0200
commit2b41619206d97b5af82c0eb08a378b96694e27ca (patch)
treefe2930193a1ae8e84bb2e964e5998830c2926ec0
parent60ddec7683499ccccf285789dc5f602138d275e6 (diff)
downloadStream-2b41619206d97b5af82c0eb08a378b96694e27ca.zip
Stream-2b41619206d97b5af82c0eb08a378b96694e27ca.tar.gz
Stream-2b41619206d97b5af82c0eb08a378b96694e27ca.tar.bz2
Add the `hasTimedOut` method.
To check whether a connection has timed out, we need to call the `getStreamMetaData` method which returns an array, and then check the value of the `timed_out` index in this array. The resulting code is: $metaData = $connection->getStreamMetaData(); if (true === $metaData['timed_out']) { // … } In some case, we need to check the time out value very often. In order to have a better readability of the code, we introduce the `hasTimeOut` shortcut method. The resulting code is then: if (true === $connection->hasTimedOut()) { // … } Much better 😀.
-rw-r--r--Stream.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/Stream.php b/Stream.php
index 2ffebf3..ca42639 100644
--- a/Stream.php
+++ b/Stream.php
@@ -438,6 +438,20 @@ abstract class Stream implements Core\Event\Listenable
}
/**
+ * Check whether the connection has timed out or not.
+ * This is basically a shortcut of `getStreamMetaData` + the `timed_out`
+ * index, but the resulting code is more readable.
+ *
+ * @return bool
+ */
+ public function hasTimedOut()
+ {
+ $metaData = $this->getStreamMetaData();
+
+ return true === $metaData['timed_out'];
+ }
+
+ /**
* Set blocking/non-blocking mode.
*
* @param bool $mode Blocking mode.