Example code is from the Chat Server Example here: https://nim-lang.org/docs/asyncnet.html
Code in question:
proc processClient(client: AsyncSocket) {.async.} =
while true:
let line = await client.recvLine()
if line.len == 0: break
for client in clients:
discard client.socket.send(line & "\c\L")
I replaced await with discard, and everything compiles, no errors, and the chat still works flawlessly.
What's the difference between await and discard in this context?
await gets you the content of a Future.
discard just discards whatever you pass as argument.
proc with {.async.} always return Future.
(usually compiler wont let you just discard/not use stuff).
Is this what you did?
let line = discard client.recvLine()
If so, then: @[anyone else] That should be a bug, shouldn't it?
Do not discard futures, if you do you will run into problems because any exceptions captured by the future will be lost. You should use asyncCheck instead which will set a callback on the future to crash your program when an unhandled exception occurs, I hope we can make discarding of futures an error at some point.
You're basically playing with fire here :)