Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ways to handle local IO
import asyncnet, asyncdispatch, threadpool
proc echoStdin =
var line = spawn stdin.readLine()
while true:
if line.isReady():
echo "You said: " & ^line
line = spawn stdin.readLine()
asyncdispatch.drain(60)
proc accept {.async.} =
var serv = newAsyncSocket()
serv.setSockOpt(OptReuseAddr, true)
serv.bindAddr(Port(1079))
serv.listen()
while true:
let client = await serv.accept()
discard
asyncCheck accept()
echoStdin()
import asyncnet, asyncdispatch, threadpool
proc echoStdin =
var line = spawn stdin.readLine()
addTimer(120, false, proc (fd: AsyncFD): bool {.closure, gcsafe.} =
if line.isReady():
echo "You said: " & ^line
line = spawn stdin.readLine()
)
proc accept {.async.} =
var serv = newAsyncSocket()
serv.setSockOpt(OptReuseAddr, true)
serv.bindAddr(Port(1079))
serv.listen()
while true:
let client = await serv.accept()
echo "Got a client"
discard
echoStdin()
asyncCheck accept()
runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.