22.03.2023, 20:18
Hi,
I am running this code to react to incoming MQTT messages.
During execution, I access storage using a semaphore, but after a while I get 'failed to create semaphore'.
In the documentation for semaphore:close(), it is stated:
Do I explicitely need to do it in the case of an eventloop? What can I do to prevent failure to create a semaphore?
Thanks
I am running this code to react to incoming MQTT messages.
During execution, I access storage using a semaphore, but after a while I get 'failed to create semaphore'.
Code:
require('sem')
-- wait for 5 seconds max before executing callback
res1, res2 = sem.runlocked('eventlock', 5, function(lockres)
-- lock acquired
if lockres then
storage.set('my_storage', '')
return true, 'ok'
-- failed to acquire lock
elseif lockres == nil then
return nil, 'failed to create semaphore'
else
return nil, 'failed to lock semaphore'
end
end)
log(res1, res2)
In the documentation for semaphore:close(), it is stated:
Quote:Closes the semaphore. Not required, semaphore handles are closed automatically when script execution endsCode:semaphore:close()
Do I explicitely need to do it in the case of an eventloop? What can I do to prevent failure to create a semaphore?
Thanks