File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,12 +59,13 @@ keep the example somewhat simple. Some shortcomings include:
5959* Buffer churn caused by allocating a new buffer for every socket read
6060 should be eliminated by reusing buffers where appropriate. Although
6161 churn doesn't increase memory footprint with reference counting, it
62- is slower than reusing buffers and might aggravate memory fragmentation.
62+ is slower than reusing buffers and might increase memory fragmentation.
6363
6464* There is no way to suspend reading or writing in the example. Adding
6565 them is straightforward: the poll set needs to be managed dynamically.
6666
6767* The example uses poll() while one should use epoll() on Linux, kqueue()
6868 on BSD systems, etc.
6969
70- * Error handling is mostly missing.
70+ * Error handling is mostly missing. Debug prints don't interact well
71+ with curses.
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ EventLoop = {
2626 nextTimerId : 1 ,
2727 minimumDelay : 1 ,
2828 minimumWait : 1 ,
29+ maximumWait : 60000 ,
2930 maxExpirys : 10 ,
3031
3132 // sockets
@@ -57,7 +58,7 @@ EventLoop.getEarliestTimer = function() {
5758
5859EventLoop . getEarliestWait = function ( ) {
5960 var t = this . getEarliestTimer ( ) ;
60- return ( t ? Math . max ( this . minimumWait , t . target - Date . now ( ) ) : null ) ;
61+ return ( t ? t . target - Date . now ( ) : null ) ;
6162}
6263
6364EventLoop . insertTimer = function ( timer ) {
@@ -252,9 +253,15 @@ EventLoop.run = function() {
252253 */
253254
254255 wait = this . getEarliestWait ( ) ;
255- if ( ! wait && poll_count === 0 ) {
256- print ( 'no active timers and no sockets to poll, exit' ) ;
257- break ;
256+ if ( wait === null ) {
257+ if ( poll_count === 0 ) {
258+ print ( 'no active timers and no sockets to poll, exit' ) ;
259+ break ;
260+ } else {
261+ wait = this . maximumWait ;
262+ }
263+ } else {
264+ wait = Math . min ( this . maximumWait , Math . max ( this . minimumWait , wait ) ) ;
258265 }
259266
260267 /*
You can’t perform that action at this time.
0 commit comments