Skip to content

Callbacks occur in same coroutine that mqtt.new is called from #20

@daurnimator

Description

@daurnimator

This causes issues for a few reasons.
e.g. Coroutines can die:

local mqtt = require("mosquitto")
print("Main thread:", coroutine.running())
local client
do
	local co = coroutine.create(function()
		print("Calling mqtt.new from:", coroutine.running())
		client = mqtt.new()
		error() -- coroutine will now be dead.
	end)
	coroutine.resume(co)
	print("THE STATUS OF ", co, "IS NOW: ", coroutine.status(co))
end
client:callback_set("ON_CONNECT", function()
	print("On Connect called from:", coroutine.running())
	client:subscribe("$SYS/#")
end)
client:callback_set("ON_MESSAGE", function(mid, topic, payload)
	print("On Message called from:", coroutine.running())
	print(topic, payload)
end)

client:connect()
client:loop_forever()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions