-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async minor #9
async minor #9
Conversation
Please elaborate, what you mean? Yes, it looks as correct mqtt packages received listening on global topic #. |
I just run test in when isMainModule when isMainModule:
proc flop() {.async.} =
let ctx = newMqttCtx("hallo")
#ctx.set_host("test.mosquitto.org", 1883)
ctx.set_host("test.mosquitto.org", 8883, true)
await ctx.start()
proc on_data(topic: string, message: string) =
echo "got ", topic, ": ", message
await ctx.subscribe("#", 2, on_data)
await ctx.publish("test1", "hallo", 2)
await sleepAsync 1000
await ctx.close()
waitFor flop() |
The listening on await ctx.publish("test1", "hallo", 2, true) # Insert true condition to wait for package confirmation (4-way handshake).
await sleepAsync 5000 # Or increase time. |
@@ -449,8 +449,8 @@ proc runConnect(ctx: MqttCtx) {.async.} = | |||
ctx.state = Error | |||
let ok = await ctx.sendConnect() | |||
if ok: | |||
asyncCheck ctx.runRx() | |||
asyncCheck ctx.runPing() | |||
await ctx.runRx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a mistake. We need the asyncCheck.
@zevv sorry, I made a mistake. We should revert "asyncCheck ctx.sendDisconnect()" to "discard await ctx.sendDisconnect()" |
Quoting flywind (2020-03-16 00:48:37)
@zevv sorry, I made a mistake. We should revert "asyncCheck
ctx.sendDisconnect()" to "discard await ctx.sendDisconnect()"
Ok!
As for other changes,the use of {.async.} is a heap allocation,so
sometimes {.async.} is expensive.Maybe we can avoid it.
Hm, that sounds a bit like premature optimization: there is tons of heap
allocations going on with all the packet building and seq handling, so
not sure if this really pays of at this time..
…--
:wq
^X^Cy^K^X^C^C^C^C
|
No description provided.