I’ve been working on a new thread system with an aim to simplify some of the callbacks used for many ObjC APIs.
On the backend it resumes each thread automatically once every frame. This allows for some pretty neat threading tricks including
Promises (which run on top of semaphores) which allow for some super simple asynchronous → synchronous conversions.
I’m just trying to gauge interest, gather suggestions and get some feedback on the API really.
If you have a similar use case that you’ve not been able to find a solution for so far let me know and I may be able to incorporate it.
Here’s how some sample usage looks in its current state:
function getResources() local p = Promise() -- Run this on the main lua thread so the callback actually works runMain(http.request, "https://baconipsum.com/api/?type=meat-and-filler¶s=1&format=text", function(data) p:resolve(data) end) -- Wait for the data to be received return p:get() end -- User Thread Thread(function() -- Download the resources print("Downloading resources") print(getResources()) print("Done") -- Only start drawing when we have the resources while true do background(180, 40, 90) -- Frame complete so do a backbuffer swap yield() end end)
^ It’s worth noting that this can run standalone in the ‘Main’ tab with no setup as long as the backend is a dependency.