1+ /**
2+ * Event loop and event loop policy.
3+ */
14module asynchronous.events ;
25
36import core.thread ;
@@ -23,17 +26,21 @@ alias Protocol = asynchronous.protocols.Protocol;
2326 */
2427interface Server
2528{
26- // / Stop serving. This leaves existing connections open.
29+ /**
30+ * Stop serving. This leaves existing connections open.
31+ */
2732 void close ();
2833
29- // / Coroutine to wait until service is closed.
34+ /**
35+ * Coroutine to wait until service is closed.
36+ */
3037 @Coroutine
3138 void waitClosed ();
3239}
3340
3441interface CallbackHandle
3542{
36- public void cancel ();
43+ void cancel ();
3744
3845 package void opCall ()
3946 {
@@ -50,10 +57,10 @@ interface SslContext
5057/**
5158 * A callback wrapper object returned by $(D_PSYMBOL EventLoop.callSoon),
5259 * $(D_PSYMBOL EventLoop.callSoonThreadsafe),
53- * $(D_PSYMBOL BaseEventLoop .callLater), and $(D_PSYMBOL BaseEventLoop .callAt).
60+ * $(D_PSYMBOL EventLoop .callLater), and $(D_PSYMBOL EventLoop .callAt).
5461 */
5562class Callback (Dg, Args... ) : CallbackHandle
56- if (isDelegate! Dg)
63+ if (isDelegate! Dg)
5764{
5865 private bool cancelled;
5966
@@ -65,7 +72,7 @@ class Callback(Dg, Args...) : CallbackHandle
6572
6673 alias ResultType = ReturnType! Dg;
6774
68- public this (EventLoop eventLoop, Dg dg, Args args)
75+ this (EventLoop eventLoop, Dg dg, Args args)
6976 {
7077 this .eventLoop = eventLoop;
7178 this .cancelled = false ;
@@ -76,7 +83,7 @@ class Callback(Dg, Args...) : CallbackHandle
7683 }
7784 }
7885
79- public override void cancel ()
86+ override void cancel ()
8087 {
8188 this .cancelled = true ;
8289 }
@@ -99,7 +106,7 @@ class Callback(Dg, Args...) : CallbackHandle
99106 }
100107 }
101108
102- override public string toString ()
109+ override string toString ()
103110 {
104111 import std.string ;
105112
@@ -209,22 +216,8 @@ abstract class EventLoop
209216 }
210217
211218 protected State state = State.STOPPED ;
212- // private size_t timerCancelledCount = 0;
213- // self._ready = collections.deque()
214- // self._scheduled = []
215- // self._default_executor = None
216- // self._internal_fds = 0
217- // self._clock_resolution = time.get_clock_info('monotonic').resolution
218- // self._exception_handler = None
219- // self._debug = (not sys.flags.ignore_environment
220- // and bool(os.environ.get('PYTHONASYNCIODEBUG')))
221- // # In debug mode, if the execution of a callback or a step of a task
222- // # exceed this duration in seconds, the slow callback/task is logged.
223- // self.slow_callback_duration = 0.1
224-
225- public :
226- // / Run an event loop
227219
220+ // Run an event loop
228221 /**
229222 * Run until $(D_PSYMBOL stop()) is called.
230223 */
@@ -315,7 +308,7 @@ public:
315308 }
316309 }
317310
318- // / Calls
311+ // Calls
319312
320313 /**
321314 * Arrange for a callback to be called as soon as possible.
@@ -326,7 +319,7 @@ public:
326319 * Any positional arguments after the callback will be passed to the
327320 * callback when it is called.
328321 *
329- * Returns: an instance of $(D_PSYMBOL Future ).
322+ * Returns: an instance of $(D_PSYMBOL Callback ).
330323 */
331324 final auto callSoon (Dg, Args... )(Dg dg, Args args)
332325 {
@@ -337,15 +330,17 @@ public:
337330 return callback;
338331 }
339332
333+ /+
340334 /**
341335 * Like $(D_PSYMBOL call_soon()), but thread safe.
342336 */
343- // ReturnType!callback callSoonThreadsafe(alias callback, Args...)(Args args)
344- // {
345- // return callLater!callback(0, args);
346- // }
337+ final auto callSoonThreadsafe(alias callback, Args...)(Args args)
338+ {
339+ return callLater!callback(0, args);
340+ }
341+ +/
347342
348- // / Delayed calls
343+ // Delayed calls
349344
350345 /**
351346 * Arrange for the callback to be called after the given delay.
@@ -394,7 +389,7 @@ public:
394389 }
395390
396391
397- // / Fibers
392+ // Fibers
398393
399394 /**
400395 * Schedule the execution of a fiber object: wrap it in a future.
@@ -407,24 +402,24 @@ public:
407402 * See_Also: $(D_PSYMBOL task()).
408403 */
409404 final auto createTask (Coroutine, Args... )(Coroutine coroutine, Args args)
410- if (isDelegate! Coroutine)
405+ if (isDelegate! Coroutine)
411406 {
412407 return new Task! (Coroutine, Args)(this , coroutine, args);
413408 }
409+ /*
410+ // Methods for interacting with threads.
414411
415- // // Methods for interacting with threads.
416-
417- // ReturnType!callback runInExecutor(alias callback, Args...)(executor, Args args);
412+ ReturnType!callback runInExecutor(alias callback, Args...)(executor, Args args);
418413
419- // void setDefaultExecutor(executor);
414+ void setDefaultExecutor(executor);
420415
421- // // Network I/O methods returning Futures.
416+ // Network I/O methods returning Futures.
422417
423- // AddressInfo[] getAddressInfo(T...)(in char[] node, T options);
418+ AddressInfo[] getAddressInfo(T...)(in char[] node, T options);
424419
425- // // def getNameInfo(sockaddr, flags = 0);
426-
427- // / Creating connections
420+ // def getNameInfo(sockaddr, flags = 0);
421+ */
422+ // Creating connections
428423
429424 /**
430425 * Create a streaming transport connection to a given Internet host and
@@ -735,7 +730,7 @@ public:
735730 *
736731 * This method is a coroutine which will try to establish the connection in
737732 * the background. When successful, the coroutine returns a $(D_PSYMBOL
738- * Tuple!(Transport, "transport", Protocol, "protocol")
733+ * Tuple!(Transport, "transport", Protocol, "protocol"))
739734 *
740735 * See the $(D_PSYMBOL EventLoop.createConnection()) method for parameters.
741736 */
@@ -972,65 +967,65 @@ public:
972967
973968 return server;
974969 }
970+ /*
971+ // Pipes and subprocesses.
975972
976- // // Pipes and subprocesses.
977-
978- // //"""Register read pipe in event loop.
973+ //"""Register read pipe in event loop.
979974
980- // // protocol_factory should instantiate object with Protocol interface.
981- // // pipe is file-like object already switched to nonblocking.
982- // // Return pair (transport, protocol), where transport support
983- // // ReadTransport interface."""
984- // // # The reason to accept file-like object instead of just file descriptor
985- // // # is: we need to own pipe and close it at transport finishing
986- // // # Can got complicated errors if pass f.fileno(),
987- // // # close fd in pipe transport then close f and vise versa.
988- // Tuple!(Transport, Protocol) connectReadPipe(Protocol function() protocol_factory,
989- // Pipe pipe);
975+ //protocol_factory should instantiate object with Protocol interface.
976+ //pipe is file-like object already switched to nonblocking.
977+ //Return pair (transport, protocol), where transport support
978+ //ReadTransport interface."""
979+ //# The reason to accept file-like object instead of just file descriptor
980+ //# is: we need to own pipe and close it at transport finishing
981+ //# Can got complicated errors if pass f.fileno(),
982+ //# close fd in pipe transport then close f and vise versa.
983+ Tuple!(Transport, Protocol) connectReadPipe(Protocol function() protocol_factory,
984+ Pipe pipe);
990985
991- // // """Register write pipe in event loop.
986+ //"""Register write pipe in event loop.
992987
993- // // protocol_factory should instantiate object with BaseProtocol interface.
994- // // Pipe is file-like object already switched to nonblocking.
995- // // Return pair (transport, protocol), where transport support
996- // // WriteTransport interface."""
997- // // # The reason to accept file-like object instead of just file descriptor
998- // // # is: we need to own pipe and close it at transport finishing
999- // // # Can got complicated errors if pass f.fileno(),
1000- // // # close fd in pipe transport then close f and vise versa.
1001- // Tuple!(Transport, Protocol) connectWritePipe(Protocol function() protocol_factory,
1002- // Pipe pipe);
988+ //protocol_factory should instantiate object with BaseProtocol interface.
989+ //Pipe is file-like object already switched to nonblocking.
990+ //Return pair (transport, protocol), where transport support
991+ //WriteTransport interface."""
992+ //# The reason to accept file-like object instead of just file descriptor
993+ //# is: we need to own pipe and close it at transport finishing
994+ //# Can got complicated errors if pass f.fileno(),
995+ //# close fd in pipe transport then close f and vise versa.
996+ Tuple!(Transport, Protocol) connectWritePipe(Protocol function() protocol_factory,
997+ Pipe pipe);
1003998
1004- // Tuple!(Transport, Protocol) processShell(Protocol function() protocol_factory,
1005- // in char[] cmd, File stdin = subprocess.PIPE, File stdout = subprocess.PIPE,
1006- // File stderr = subprocess.PIPE);
999+ Tuple!(Transport, Protocol) processShell(Protocol function() protocol_factory,
1000+ in char[] cmd, File stdin = subprocess.PIPE, File stdout = subprocess.PIPE,
1001+ File stderr = subprocess.PIPE);
10071002
1008- // Tuple!(Transport, Protocol) processProcess(Protocol function() protocol_factory,
1009- // in char[][] args, File stdin = subprocess.PIPE, File stdout = subprocess.PIPE,
1010- // File stderr = subprocess.PIPE);
1003+ Tuple!(Transport, Protocol) processProcess(Protocol function() protocol_factory,
1004+ in char[][] args, File stdin = subprocess.PIPE, File stdout = subprocess.PIPE,
1005+ File stderr = subprocess.PIPE);
10111006
1012- // // # Ready-based callback registration methods.
1013- // // # The add_*() methods return None.
1014- // // # The remove_*() methods return True if something was removed,
1015- // // # False if there was nothing to delete.
1007+ //# Ready-based callback registration methods.
1008+ //# The add_*() methods return None.
1009+ //# The remove_*() methods return True if something was removed,
1010+ //# False if there was nothing to delete.
10161011
1017- // void addReader(int fd, void delegate() callback);
1012+ void addReader(int fd, void delegate() callback);
10181013
1019- // void removeReader(int fd);
1014+ void removeReader(int fd);
10201015
1021- // void addWriter(int fd, void delegate() callback);
1016+ void addWriter(int fd, void delegate() callback);
10221017
1023- // void removeWriter(int fd);
1018+ void removeWriter(int fd);
10241019
1025- // // # Completion based I/O methods returning Futures.
1020+ // # Completion based I/O methods returning Futures.
10261021
1027- // ptrdiff_t socketReceive(Socket sock, void[] buf);
1022+ ptrdiff_t socketReceive(Socket sock, void[] buf);
10281023
1029- // ptrdiff_t socketSend(Socket sock, void[] buf);
1024+ ptrdiff_t socketSend(Socket sock, void[] buf);
10301025
1031- // Socket socketAccept(Socket sock);
1032-
1033- // / Resolve host name
1026+ Socket socketAccept(Socket sock);
1027+ */
1028+ // Resolve host name
10341029
10351030 @Coroutine
10361031 AddressInfo[] getAddressInfo (in char [] host, in char [] service,
@@ -1040,32 +1035,28 @@ public:
10401035 AddressInfoFlags addressInfoFlags = UNSPECIFIED ! AddressInfoFlags);
10411036
10421037
1043- // / Signal handling.
1038+ // Signal handling.
10441039 version (Posix )
10451040 {
10461041 void addSignalHandler (int sig, void delegate () handler);
10471042
10481043 void removeSignalHandler (int sig);
10491044 }
10501045
1051- // / Error handlers.
1052- // void setExceptionHandler(void function(EventLoop, ExceptionContext) handler);
1046+ // Error handlers.
1047+ /+
1048+ void setExceptionHandler(void function(EventLoop, ExceptionContext) handler);
10531049
1054- // void defaultExceptionHandler(ExceptionContext context);
1050+ void defaultExceptionHandler(ExceptionContext context);
10551051
1056- // void callExceptionHandler(ExceptionContext context);
1052+ void callExceptionHandler(ExceptionContext context);
1053+ +/
10571054
10581055 override string toString ()
10591056 {
10601057 return " %s(%s)" .format(typeid (this ), this .state);
10611058 }
10621059
1063- // // # Debug flag management.
1064-
1065- // bool getDebug();
1066-
1067- // void setDebug(bool enabled);
1068-
10691060protected :
10701061
10711062 void scheduleCallback (CallbackHandle callback);
0 commit comments