mirror of
https://github.com/danog/amp.git
synced 2024-12-02 17:37:50 +01:00
Merge pull request #26 from async-interop/loop-name
Rename EventLoop → Loop and EventLoopDriver → LoopDriver
This commit is contained in:
commit
deb801b941
@ -2,10 +2,10 @@
|
||||
|
||||
namespace Interop\Async\EventLoop;
|
||||
|
||||
final class EventLoop
|
||||
final class Loop
|
||||
{
|
||||
/**
|
||||
* @var EventLoopDriver
|
||||
* @var LoopDriver
|
||||
*/
|
||||
private static $driver = null;
|
||||
|
||||
@ -13,11 +13,11 @@ final class EventLoop
|
||||
* Execute a callback within the scope of an event loop driver.
|
||||
*
|
||||
* @param callable $callback The callback to execute
|
||||
* @param EventLoopDriver $driver The event loop driver
|
||||
* @param LoopDriver $driver The event loop driver
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function execute(callable $callback, EventLoopDriver $driver)
|
||||
public static function execute(callable $callback, LoopDriver $driver)
|
||||
{
|
||||
$previousDriver = self::$driver;
|
||||
|
||||
@ -34,8 +34,8 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Retrieve the event loop driver that is in scope.
|
||||
*
|
||||
* @return EventLoopDriver
|
||||
*
|
||||
* @return LoopDriver
|
||||
*/
|
||||
public static function get()
|
||||
{
|
||||
@ -48,7 +48,7 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Stop the event loop.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function stop()
|
||||
@ -58,9 +58,9 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Defer the execution of a callback.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to defer.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function defer(callable $callback)
|
||||
@ -70,10 +70,10 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to delay.
|
||||
* @param int $time The amount of time, in milliseconds, to delay the execution for.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function delay(callable $callback, $time)
|
||||
@ -83,10 +83,10 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to repeat.
|
||||
* @param int $interval The time interval, in milliseconds, to wait between executions.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function repeat(callable $callback, $interval)
|
||||
@ -96,10 +96,10 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Execute a callback when a stream resource becomes readable.
|
||||
*
|
||||
*
|
||||
* @param resource $stream The stream to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function onReadable($stream, callable $callback)
|
||||
@ -109,10 +109,10 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Execute a callback when a stream resource becomes writable.
|
||||
*
|
||||
*
|
||||
* @param resource $stream The stream to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function onWritable($stream, callable $callback)
|
||||
@ -122,10 +122,10 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Execute a callback when a signal is received.
|
||||
*
|
||||
*
|
||||
* @param int $signo The signal number to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function onSignal($signo, callable $callback)
|
||||
@ -135,9 +135,9 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Execute a callback when an error occurs.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public static function onError(callable $callback)
|
||||
@ -147,9 +147,9 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Enable an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function enable($eventIdentifier)
|
||||
@ -159,9 +159,9 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Disable an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function disable($eventIdentifier)
|
||||
@ -171,9 +171,9 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Cancel an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function cancel($eventIdentifier)
|
||||
@ -183,11 +183,11 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Reference an event.
|
||||
*
|
||||
*
|
||||
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function reference($eventIdentifier)
|
||||
@ -197,12 +197,12 @@ final class EventLoop
|
||||
|
||||
/**
|
||||
* Unreference an event.
|
||||
*
|
||||
*
|
||||
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
|
||||
* referenced by default.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function unreference($eventIdentifier)
|
@ -2,136 +2,136 @@
|
||||
|
||||
namespace Interop\Async\EventLoop;
|
||||
|
||||
interface EventLoopDriver
|
||||
interface LoopDriver
|
||||
{
|
||||
/**
|
||||
* Start the event loop.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run();
|
||||
|
||||
/**
|
||||
* Stop the event loop.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stop();
|
||||
|
||||
/**
|
||||
* Defer the execution of a callback.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to defer.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function defer(callable $callback);
|
||||
|
||||
/**
|
||||
* Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to delay.
|
||||
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function delay(callable $callback, $delay);
|
||||
|
||||
/**
|
||||
* Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to repeat.
|
||||
* @param int $interval The time interval, in milliseconds, to wait between executions.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function repeat(callable $callback, $interval);
|
||||
|
||||
/**
|
||||
* Execute a callback when a stream resource becomes readable.
|
||||
*
|
||||
*
|
||||
* @param resource $stream The stream to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function onReadable($stream, callable $callback);
|
||||
|
||||
/**
|
||||
* Execute a callback when a stream resource becomes writable.
|
||||
*
|
||||
*
|
||||
* @param resource $stream The stream to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function onWritable($stream, callable $callback);
|
||||
|
||||
/**
|
||||
* Execute a callback when a signal is received.
|
||||
*
|
||||
*
|
||||
* @param int $signo The signal number to monitor.
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function onSignal($signo, callable $callback);
|
||||
|
||||
/**
|
||||
* Execute a callback when an error occurs.
|
||||
*
|
||||
*
|
||||
* @param callable $callback The callback to execute.
|
||||
*
|
||||
*
|
||||
* @return string An identifier that can be used to cancel, enable or disable the event.
|
||||
*/
|
||||
public function onError(callable $callback);
|
||||
|
||||
/**
|
||||
* Enable an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable($eventIdentifier);
|
||||
|
||||
/**
|
||||
* Disable an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable($eventIdentifier);
|
||||
|
||||
/**
|
||||
* Cancel an event.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel($eventIdentifier);
|
||||
|
||||
/**
|
||||
* Reference an event.
|
||||
*
|
||||
*
|
||||
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reference($eventIdentifier);
|
||||
|
||||
/**
|
||||
* Unreference an event.
|
||||
*
|
||||
*
|
||||
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
|
||||
* referenced by default.
|
||||
*
|
||||
*
|
||||
* @param string $eventIdentifier The event identifier.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unreference($eventIdentifier);
|
Loading…
Reference in New Issue
Block a user