1
0
mirror of https://github.com/danog/amp.git synced 2024-12-04 10:28:01 +01:00
amp/src/LoopDriver.php

158 lines
5.3 KiB
PHP
Raw Normal View History

2016-01-20 12:01:40 +01:00
<?php
namespace Interop\Async;
2016-01-20 12:01:40 +01:00
interface LoopDriver
2016-01-20 12:01:40 +01:00
{
2016-02-17 16:25:39 +01:00
/**
2016-03-14 11:56:31 +01:00
* Start the event loop.
*
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-02-17 16:25:39 +01:00
* @return void
*/
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-19 17:21:26 +02:00
* @param callable(string $watcherId, mixed $data) $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.
*
* @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.
*
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
* @param callable(string $watcherId, mixed $data) $callback The callback to delay.
2016-05-15 00:13:35 +02:00
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
*
* @return string An identifier that can be used to cancel, enable or disable the watcher.
2016-02-17 16:25:39 +01:00
*/
public function delay($delay, callable $callback, $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.
*
* @param int $interval The time interval, in milliseconds, to wait between executions.
* @param callable(string $watcherId, mixed $data) $callback The callback to repeat.
2016-05-15 00:13:35 +02:00
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
*
* @return string An identifier that can be used to cancel, enable or disable the watcher.
2016-02-17 16:25:39 +01:00
*/
public function repeat($interval, 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 readable.
*
2016-03-14 11:56:31 +01:00
* @param resource $stream The stream to monitor.
2016-05-19 17:21:26 +02:00
* @param callable(string $watcherId, resource $stream, mixed $data) $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.
*
* @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-03-14 11:56:31 +01:00
* @param resource $stream The stream to monitor.
2016-05-19 17:21:26 +02:00
* @param callable(string $watcherId, resource $stream, mixed $data) $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.
*
* @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-03-14 11:56:31 +01:00
* @param int $signo The signal number to monitor.
2016-05-19 17:21:26 +02:00
* @param callable(string $watcherId, int $signo, mixed $data) $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.
*
* @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
/**
* Enable a watcher.
*
2016-05-19 17:21:26 +02:00
* @param string $watcherId The watcher identifier.
*
* @return void
2016-02-17 16:25:39 +01:00
*/
2016-05-19 17:21:26 +02:00
public function enable($watcherId);
/**
* Disable a watcher.
*
2016-05-19 17:21:26 +02:00
* @param string $watcherId The watcher identifier.
*
* @return void
*/
2016-05-19 17:21:26 +02:00
public function disable($watcherId);
/**
* Cancel a watcher.
*
2016-05-19 17:21:26 +02:00
* @param string $watcherId The watcher identifier.
*
* @return void
*/
2016-05-19 17:21:26 +02:00
public function cancel($watcherId);
2016-03-23 10:47:18 +01:00
/**
* Reference a watcher.
*
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-19 17:21:26 +02:00
* @param string $watcherId The watcher identifier.
*
2016-03-23 10:47:18 +01:00
* @return void
*/
2016-05-19 17:21:26 +02:00
public function reference($watcherId);
2016-03-23 10:47:18 +01:00
/**
* Unreference a watcher.
*
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-19 17:21:26 +02:00
* @param string $watcherId The watcher identifier.
*
2016-03-23 10:47:18 +01:00
* @return void
*/
2016-05-19 17:21:26 +02:00
public function unreference($watcherId);
/**
* Set a callback to be executed when an error occurs.
*
* Subsequent calls to this method will overwrite the previous handler.
*
* @param callable(\Throwable|\Exception $error)|null $callback The callback to execute; null will clear the current handler.
*
* @return void
*/
public function setErrorHandler(callable $callback = null);
/**
* Get the underlying loop handle.
*
* Example: the uv_loop resource for libuv or the EvLoop object for libev or null for a native driver
*
* Note: This function is *not* exposed in the Loop class; users shall access it directly on the respective loop instance.
*
* @return null|object|resource The loop handle the event loop operates on. Null if there is none.
*/
public function getHandle();
2016-01-20 12:01:40 +01:00
}