08.02.2019, 10:24
Saving current PID might still lead to race conditions if two scripts execute in really short time period. The more elegant way is to use a resident script with two copas threads - one for bus monitoring and another for sequence.
Code:
if not client then
require('copas')
function eventhandler(...)
log('event', ...)
end
client = require('localbus').new()
client:sethandler('groupwrite', eventhandler)
client:sethandler('groupresponse', eventhandler)
copas.addserver(client.sock, function()
client.sock = copas.wrap(client.sock)
while true do
client:step()
end
end, 1)
copas.addthread(function()
while true do
copas.sleep(0.5)
end
end)
end
copas.step()