I think I should note that I'm not sure if you really intended using `async*`
with threadpools. Async stuff in Nim is still single threaded (even though its
concurrent, it is not parallel).
You should instead use a single-threaded program, declare `loopThr` as
`{.async.}` and then use `await` in `loopThr`.
Please let me know if you need any help with the `async` stuff, it can indeed
be a bit weird...
I can't test this now, but try:
type
Server* = ref object
socket: AsyncSocket
started*: bool
...
...
proc newServer*(): Server =
Server(
socket: nil,
false,
...
)
proc loopThr(server: Server, serverPort: int) {.async.} =
server.socket = newAsyncSocket()
server.socket.bindAddr(serverPort.Port)
server.socket.listen()
server.started = true
# server.loopTask = loop(server) # not sure what this is here
# waitFor server.loopTask # you can do some non-blocking IO now. eg:
let line = await server.socket.recvLine() # this will not block
proc start*(server: Server, serverPort: int) =
waitFor loopThr(server, serverPort) # changed this to ``waitFor`` for
example's sake.
sleep(100)