Skip to content

Commit 5a84c83

Browse files
committed
Add Loop::supports to check for optional features
1 parent deb801b commit 5a84c83

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Loop.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ public static function unreference($eventIdentifier)
210210
self::get()->unreference($eventIdentifier);
211211
}
212212

213+
/**
214+
* Check whether an optional feature is supported by the current event loop
215+
* driver.
216+
*
217+
* @param int $feature Loop::FEATURE_* constant
218+
*
219+
* @return bool
220+
*/
221+
public static function supports($feature) {
222+
return self::get()->supports($feature);
223+
}
224+
213225
/**
214226
* Disable construction as this is a static class.
215227
*/

src/LoopDriver.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
interface LoopDriver
66
{
7+
const FEATURE_SIGNAL_HANDLING = 0b001;
8+
79
/**
810
* Start the event loop.
911
*
@@ -135,4 +137,18 @@ public function reference($eventIdentifier);
135137
* @return void
136138
*/
137139
public function unreference($eventIdentifier);
140+
141+
/**
142+
* Check whether an optional features is supported by this implementation
143+
* and system.
144+
*
145+
* Example: If the implementation can handle signals using PCNTL, but the
146+
* PCNTL extension is not available, the feature MUST NOT be marked as
147+
* supported.
148+
*
149+
* @param int $feature FEATURE constant
150+
*
151+
* @return bool
152+
*/
153+
public function supports($feature);
138154
}

src/UnsupportedFeatureException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Interop\Async\EventLoop;
4+
5+
/**
6+
* Must be thrown if an optional feature is not supported by the current driver
7+
* or system.
8+
*/
9+
class UnsupportedFeatureException extends \RuntimeException { }

0 commit comments

Comments
 (0)