1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 18:07:57 +01:00

Merge pull request #26 from async-interop/loop-name

Rename EventLoop → Loop and EventLoopDriver → LoopDriver
This commit is contained in:
Bob Weinand 2016-05-12 18:26:14 +02:00
commit deb801b941
2 changed files with 62 additions and 62 deletions

View File

@ -2,10 +2,10 @@
namespace Interop\Async\EventLoop; namespace Interop\Async\EventLoop;
final class EventLoop final class Loop
{ {
/** /**
* @var EventLoopDriver * @var LoopDriver
*/ */
private static $driver = null; private static $driver = null;
@ -13,11 +13,11 @@ final class EventLoop
* Execute a callback within the scope of an event loop driver. * Execute a callback within the scope of an event loop driver.
* *
* @param callable $callback The callback to execute * @param callable $callback The callback to execute
* @param EventLoopDriver $driver The event loop driver * @param LoopDriver $driver The event loop driver
* *
* @return void * @return void
*/ */
public static function execute(callable $callback, EventLoopDriver $driver) public static function execute(callable $callback, LoopDriver $driver)
{ {
$previousDriver = self::$driver; $previousDriver = self::$driver;
@ -34,8 +34,8 @@ final class EventLoop
/** /**
* Retrieve the event loop driver that is in scope. * Retrieve the event loop driver that is in scope.
* *
* @return EventLoopDriver * @return LoopDriver
*/ */
public static function get() public static function get()
{ {
@ -48,7 +48,7 @@ final class EventLoop
/** /**
* Stop the event loop. * Stop the event loop.
* *
* @return void * @return void
*/ */
public static function stop() public static function stop()
@ -58,9 +58,9 @@ final class EventLoop
/** /**
* Defer the execution of a callback. * Defer the execution of a callback.
* *
* @param callable $callback The callback to defer. * @param callable $callback The callback to defer.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function defer(callable $callback) 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. * Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
* *
* @param callable $callback The callback to delay. * @param callable $callback The callback to delay.
* @param int $time The amount of time, in milliseconds, to delay the execution for. * @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. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function delay(callable $callback, $time) 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. * Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
* *
* @param callable $callback The callback to repeat. * @param callable $callback The callback to repeat.
* @param int $interval The time interval, in milliseconds, to wait between executions. * @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. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function repeat(callable $callback, $interval) public static function repeat(callable $callback, $interval)
@ -96,10 +96,10 @@ final class EventLoop
/** /**
* Execute a callback when a stream resource becomes readable. * Execute a callback when a stream resource becomes readable.
* *
* @param resource $stream The stream to monitor. * @param resource $stream The stream to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function onReadable($stream, callable $callback) public static function onReadable($stream, callable $callback)
@ -109,10 +109,10 @@ final class EventLoop
/** /**
* Execute a callback when a stream resource becomes writable. * Execute a callback when a stream resource becomes writable.
* *
* @param resource $stream The stream to monitor. * @param resource $stream The stream to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function onWritable($stream, callable $callback) public static function onWritable($stream, callable $callback)
@ -122,10 +122,10 @@ final class EventLoop
/** /**
* Execute a callback when a signal is received. * Execute a callback when a signal is received.
* *
* @param int $signo The signal number to monitor. * @param int $signo The signal number to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function onSignal($signo, callable $callback) public static function onSignal($signo, callable $callback)
@ -135,9 +135,9 @@ final class EventLoop
/** /**
* Execute a callback when an error occurs. * Execute a callback when an error occurs.
* *
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public static function onError(callable $callback) public static function onError(callable $callback)
@ -147,9 +147,9 @@ final class EventLoop
/** /**
* Enable an event. * Enable an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public static function enable($eventIdentifier) public static function enable($eventIdentifier)
@ -159,9 +159,9 @@ final class EventLoop
/** /**
* Disable an event. * Disable an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public static function disable($eventIdentifier) public static function disable($eventIdentifier)
@ -171,9 +171,9 @@ final class EventLoop
/** /**
* Cancel an event. * Cancel an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public static function cancel($eventIdentifier) public static function cancel($eventIdentifier)
@ -183,11 +183,11 @@ final class EventLoop
/** /**
* Reference an event. * Reference an event.
* *
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default. * 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. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public static function reference($eventIdentifier) public static function reference($eventIdentifier)
@ -197,12 +197,12 @@ final class EventLoop
/** /**
* Unreference an event. * Unreference an event.
* *
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all * The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
* referenced by default. * referenced by default.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public static function unreference($eventIdentifier) public static function unreference($eventIdentifier)

View File

@ -2,136 +2,136 @@
namespace Interop\Async\EventLoop; namespace Interop\Async\EventLoop;
interface EventLoopDriver interface LoopDriver
{ {
/** /**
* Start the event loop. * Start the event loop.
* *
* @return void * @return void
*/ */
public function run(); public function run();
/** /**
* Stop the event loop. * Stop the event loop.
* *
* @return void * @return void
*/ */
public function stop(); public function stop();
/** /**
* Defer the execution of a callback. * Defer the execution of a callback.
* *
* @param callable $callback The callback to defer. * @param callable $callback The callback to defer.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function defer(callable $callback); public function defer(callable $callback);
/** /**
* Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed. * Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
* *
* @param callable $callback The callback to delay. * @param callable $callback The callback to delay.
* @param int $delay The amount of time, in milliseconds, to delay the execution for. * @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. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function delay(callable $callback, $delay); public function delay(callable $callback, $delay);
/** /**
* Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed. * Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
* *
* @param callable $callback The callback to repeat. * @param callable $callback The callback to repeat.
* @param int $interval The time interval, in milliseconds, to wait between executions. * @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. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function repeat(callable $callback, $interval); public function repeat(callable $callback, $interval);
/** /**
* Execute a callback when a stream resource becomes readable. * Execute a callback when a stream resource becomes readable.
* *
* @param resource $stream The stream to monitor. * @param resource $stream The stream to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function onReadable($stream, callable $callback); public function onReadable($stream, callable $callback);
/** /**
* Execute a callback when a stream resource becomes writable. * Execute a callback when a stream resource becomes writable.
* *
* @param resource $stream The stream to monitor. * @param resource $stream The stream to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function onWritable($stream, callable $callback); public function onWritable($stream, callable $callback);
/** /**
* Execute a callback when a signal is received. * Execute a callback when a signal is received.
* *
* @param int $signo The signal number to monitor. * @param int $signo The signal number to monitor.
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function onSignal($signo, callable $callback); public function onSignal($signo, callable $callback);
/** /**
* Execute a callback when an error occurs. * Execute a callback when an error occurs.
* *
* @param callable $callback The callback to execute. * @param callable $callback The callback to execute.
* *
* @return string An identifier that can be used to cancel, enable or disable the event. * @return string An identifier that can be used to cancel, enable or disable the event.
*/ */
public function onError(callable $callback); public function onError(callable $callback);
/** /**
* Enable an event. * Enable an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public function enable($eventIdentifier); public function enable($eventIdentifier);
/** /**
* Disable an event. * Disable an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public function disable($eventIdentifier); public function disable($eventIdentifier);
/** /**
* Cancel an event. * Cancel an event.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public function cancel($eventIdentifier); public function cancel($eventIdentifier);
/** /**
* Reference an event. * Reference an event.
* *
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default. * 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. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public function reference($eventIdentifier); public function reference($eventIdentifier);
/** /**
* Unreference an event. * Unreference an event.
* *
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all * The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
* referenced by default. * referenced by default.
* *
* @param string $eventIdentifier The event identifier. * @param string $eventIdentifier The event identifier.
* *
* @return void * @return void
*/ */
public function unreference($eventIdentifier); public function unreference($eventIdentifier);