How to start a parallel program from within an api

Started by Flexico, Mar 10, 2022, 08:12 PM

Previous topic - Next topic

Flexico

I have an API I use in many of my programs, and I'm trying to add a function that can constantly be listening for modem messages and appending them to a file, and then a function that will return them one at a time, to avoid missing any due to loop timing. My first attempt is to run a shell.run("bg [programName]") command, but apparently API's aren't allowed to do that. What would you recommend?

Lupus590

CC doesn't really have a way to run stuff in the background like this. There are a couple of dirty tricks that you could do but since your use case is quite specific I would instead recommend this.

Lyqyd's touchpoint API has a function that transforms events, but it's written in such a way that if it can't transform the event (either the event is not a mouse_click/monitor_touch or the click/touch doesn't line up with a known button) then it seamlessly passes the event through. So with Touchpoint one can do something like this:

-- fairly sure I'm using the touchpoint API wrong, but the principle still applies
local event = {touchpoint.processEvents(os.pullEvent())}

If event[1] == "touchpoint_button" then
  -- ...
end


You could do a similar thing, your processEvents function could watch for modem_message events and record those before passing them to the calling code, any non modem events get passed without being recorded.

There are other things that you could do but this is the cleanest in my opinion. If the client code wants this to happen in the background then you would have provided them with the tools for them to do so.

Flexico

Hmm, ok, thanks! I'll have to try that out~