3 ms·
There are ways to get around this, the way that I have done it in Nim is via a `multisync` macro: proc readLine(s: Socket | AsyncSocket): Future[string] {.
by dom96 7y ago
There are ways to get around this, the way that I have done it in Nim is via a `multisync` macro:
proc readLine(s: Socket | AsyncSocket): Future[string] {.multisync.} =
while true:
let c = await s.recv(1)
case c
of '\n':
return
else:
result.add(c)
This is equivalent to defining two `readLine` procedures, one performing synchronous IO and accepting a `Socket` and another performing asynchronous IO and accepting an `AsyncSocket`. It works very well in practice.