This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

universal MQTT / Timer / Localbus event loop
#9
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'.

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:
Code:
semaphore:close()
Closes the semaphore. Not required, semaphore handles are closed automatically when script execution ends

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
Reply


Messages In This Thread
RE: universal MQTT / Timer / Localbus event loop - by spyder - 22.03.2023, 20:18

Forum Jump: