summary refs log tree commit diff stats
path: root/lib/pure/asyncdispatch.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/asyncdispatch.nim')
-rw-r--r--lib/pure/asyncdispatch.nim18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index 8c4a0e41d..58028847e 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -1062,17 +1062,27 @@ else:
           let currentCBs = data.readCBs
           data.readCBs = @[]
           for cb in currentCBs:
-            if not cb(data.fd):
-              # Callback wants to be called again.
+            if data.readCBs.len > 0:
+              # A callback has already returned with EAGAIN, don't call any
+              # others until next `poll`.
               data.readCBs.add(cb)
+            else:
+              if not cb(data.fd):
+                # Callback wants to be called again.
+                data.readCBs.add(cb)
 
         if EvWrite in info.events or info.events == {EvError}:
           let currentCBs = data.writeCBs
           data.writeCBs = @[]
           for cb in currentCBs:
-            if not cb(data.fd):
-              # Callback wants to be called again.
+            if data.writeCBs.len > 0:
+              # A callback has already returned with EAGAIN, don't call any
+              # others until next `poll`.
               data.writeCBs.add(cb)
+            else:
+              if not cb(data.fd):
+                # Callback wants to be called again.
+                data.writeCBs.add(cb)
 
         if info.key in p.selector:
           var newEvents: set[Event]