Skip to content

Commit 71fcb29

Browse files
Merge branch 'master' of github.com:async-interop/event-loop into HEAD
2 parents 54c4ded + eca2278 commit 71fcb29

File tree

2 files changed

+138
-7
lines changed

2 files changed

+138
-7
lines changed

src/EventLoopDriver.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
namespace Interop\Async\EventLoop;
4+
5+
interface EventLoopDriver
6+
{
7+
/**
8+
* Start the event loop.
9+
*
10+
* @return void
11+
*/
12+
public function run();
13+
14+
/**
15+
* Stop the event loop.
16+
*
17+
* @return void
18+
*/
19+
public function stop();
20+
21+
/**
22+
* Defer the execution of a callback.
23+
*
24+
* @param callable $callback The callback to defer.
25+
*
26+
* @return string An identifier that can be used to cancel, enable or disable the event.
27+
*/
28+
public function defer(callable $callback);
29+
30+
/**
31+
* Delay the execution of a callback. The time delay is approximate and accuracy is not guaranteed.
32+
*
33+
* @param callable $callback The callback to delay.
34+
* @param float $time The amount of time, in seconds, to delay the execution for.
35+
*
36+
* @return string An identifier that can be used to cancel, enable or disable the event.
37+
*/
38+
public function delay(callable $callback, float $time);
39+
40+
/**
41+
* Repeatedly execute a callback. The interval between executions is approximate and accuracy is not guaranteed.
42+
*
43+
* @param callable $callback The callback to repeat.
44+
* @param float $interval The time interval, in seconds, to wait between executions.
45+
*
46+
* @return string An identifier that can be used to cancel, enable or disable the event.
47+
*/
48+
public function repeat(callable $callback, float $interval);
49+
50+
/**
51+
* Execute a callback when a stream resource becomes readable.
52+
*
53+
* @param resource $stream The stream to monitor.
54+
* @param callable $callback The callback to execute.
55+
*
56+
* @return string An identifier that can be used to cancel, enable or disable the event.
57+
*/
58+
public function onReadable($stream, callable $callback);
59+
60+
/**
61+
* Execute a callback when a stream resource becomes writable.
62+
*
63+
* @param resource $stream The stream to monitor.
64+
* @param callable $callback The callback to execute.
65+
*
66+
* @return string An identifier that can be used to cancel, enable or disable the event.
67+
*/
68+
public function onWritable($stream, callable $callback);
69+
70+
/**
71+
* Execute a callback when a signal is received.
72+
*
73+
* @param int $signo The signal number to monitor.
74+
* @param callable $callback The callback to execute.
75+
*
76+
* @return string An identifier that can be used to cancel, enable or disable the event.
77+
*/
78+
public function onSignal(int $signo, callable $callback);
79+
80+
/**
81+
* Execute a callback when an error occurs.
82+
*
83+
* @param callable $callback The callback to execute.
84+
*
85+
* @return string An identifier that can be used to cancel, enable or disable the event.
86+
*/
87+
public function onError(callable $callback);
88+
89+
/**
90+
* Enable an event.
91+
*
92+
* @param string $eventIdentifier The event identifier.
93+
*
94+
* @return void
95+
*/
96+
public function enable(string $eventIdentifier);
97+
98+
/**
99+
* Disable an event.
100+
*
101+
* @param string $eventIdentifier The event identifier.
102+
*
103+
* @return void
104+
*/
105+
public function disable(string $eventIdentifier);
106+
107+
/**
108+
* Cancel an event.
109+
*
110+
* @param string $eventIdentifier The event identifier.
111+
*
112+
* @return void
113+
*/
114+
public function cancel(string $eventIdentifier);
115+
116+
/**
117+
* Reference an event.
118+
*
119+
* This will keep the event loop alive whilst the event is still being monitored. Events have this state by default.
120+
*
121+
* @param string $eventIdentifier The event identifier.
122+
*
123+
* @return void
124+
*/
125+
public function reference(string $eventIdentifier);
126+
127+
/**
128+
* Unreference an event.
129+
*
130+
* The event loop should exit the run method when only unreferenced events are still being monitored. Events are all
131+
* referenced by default.
132+
*
133+
* @param string $eventIdentifier The event identifier.
134+
*
135+
* @return void
136+
*/
137+
public function unreference(string $eventIdentifier);
138+
}

src/EventLoopInterface.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)