2016-01-20 12:01:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Interop\Async\EventLoop;
|
|
|
|
|
2016-05-12 17:57:02 +02:00
|
|
|
interface LoopDriver
|
2016-01-20 12:01:40 +01:00
|
|
|
{
|
2016-05-13 23:41:54 +02:00
|
|
|
const FEATURE_SIGNAL_HANDLING = 0b001;
|
|
|
|
|
2016-02-17 16:25:39 +01:00
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Start the event loop.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-02-17 16:25:39 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-03-14 11:56:31 +01:00
|
|
|
public function run();
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Stop the event loop.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-02-17 16:25:39 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-03-01 01:52:59 +01:00
|
|
|
public function stop();
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Defer the execution of a callback.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(mixed $data, string $watcherIdentifier) $callback The callback to defer.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function defer(callable $callback, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(mixed $data, string $watcherIdentifier) $callback The callback to delay.
|
2016-05-12 12:28:46 +02:00
|
|
|
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function delay(callable $callback, $delay, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(mixed $data, string $watcherIdentifier) $callback The callback to repeat.
|
2016-05-12 12:28:46 +02:00
|
|
|
* @param int $interval The time interval, in milliseconds, to wait between executions.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function repeat(callable $callback, $interval, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Execute a callback when a stream resource becomes readable.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-14 11:56:31 +01:00
|
|
|
* @param resource $stream The stream to monitor.
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(resource $stream, mixed $data, string $watcherIdentifier) $callback The callback to execute.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function onReadable($stream, callable $callback, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Execute a callback when a stream resource becomes writable.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-14 11:56:31 +01:00
|
|
|
* @param resource $stream The stream to monitor.
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(resource $stream, mixed $data, string $watcherIdentifier) $callback The callback to execute.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function onWritable($stream, callable $callback, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Execute a callback when a signal is received.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-14 11:56:31 +01:00
|
|
|
* @param int $signo The signal number to monitor.
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(int $signo, mixed $data, string $watcherIdentifier) $callback The callback to execute.
|
2016-05-15 00:13:35 +02:00
|
|
|
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:13:35 +02:00
|
|
|
public function onSignal($signo, callable $callback, $data = null);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-14 11:56:31 +01:00
|
|
|
* Execute a callback when an error occurs.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:14:33 +02:00
|
|
|
* @param callable(\Throwable|\Exception $exception) $callback The callback to execute.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @return string An identifier that can be used to cancel, enable or disable the watcher.
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-03-01 01:52:59 +01:00
|
|
|
public function onError(callable $callback);
|
2016-02-17 16:25:39 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-15 00:19:05 +02:00
|
|
|
* Enable a watcher.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @param string $watcherIdentifier The watcher identifier.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-01 01:52:59 +01:00
|
|
|
* @return void
|
2016-02-17 16:25:39 +01:00
|
|
|
*/
|
2016-05-15 00:19:05 +02:00
|
|
|
public function enable($watcherIdentifier);
|
2016-03-01 01:52:59 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-15 00:19:05 +02:00
|
|
|
* Disable a watcher.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @param string $watcherIdentifier The watcher identifier.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-01 01:52:59 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-15 00:19:05 +02:00
|
|
|
public function disable($watcherIdentifier);
|
2016-03-01 01:52:59 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-15 00:19:05 +02:00
|
|
|
* Cancel a watcher.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @param string $watcherIdentifier The watcher identifier.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-01 01:52:59 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-15 00:19:05 +02:00
|
|
|
public function cancel($watcherIdentifier);
|
2016-03-23 10:47:18 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-15 00:19:05 +02:00
|
|
|
* Reference a watcher.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-23 10:47:18 +01:00
|
|
|
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @param string $watcherIdentifier The watcher identifier.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-23 10:47:18 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-15 00:19:05 +02:00
|
|
|
public function reference($watcherIdentifier);
|
2016-03-23 10:47:18 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-15 00:19:05 +02:00
|
|
|
* Unreference a watcher.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-23 10:47:18 +01:00
|
|
|
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
|
|
|
|
* referenced by default.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-05-15 00:19:05 +02:00
|
|
|
* @param string $watcherIdentifier The watcher identifier.
|
2016-05-12 17:57:02 +02:00
|
|
|
*
|
2016-03-23 10:47:18 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-15 00:19:05 +02:00
|
|
|
public function unreference($watcherIdentifier);
|
2016-05-13 23:41:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an optional features is supported by this implementation
|
|
|
|
* and system.
|
|
|
|
*
|
|
|
|
* Example: If the implementation can handle signals using PCNTL, but the
|
|
|
|
* PCNTL extension is not available, the feature MUST NOT be marked as
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* @param int $feature FEATURE constant
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function supports($feature);
|
2016-01-20 12:01:40 +01:00
|
|
|
}
|