I’m looking for ideas on how create a long running function that does not block events/timers/etc.
My guess is my function could take a couple minutes to run, and I’d run it at some inconsequential time during each night.
I’ve got a couple of ideas I’m trying, both basically involve splitting the long running function down to as small (time execution wise) as makes sense in to sub-functions. Then from there my two ideas are:
mgos_wdt_feed()before each sub-function is executed
- Schedule the sub-functions with
mgos_set_timer(0, 0, sub_function, NULL);and then manage the overall state somehow between sub-functions.
Option 2 feels like the right way, but I’m struggling trying to work out how best to manage state between each sub-function run. My only idea is via some static enum that tracks progress that I increment “state” with each sub-function, then re-schedule the main function at the end of each sub-function.
Any ideas or even general programming principals/patterns would be much appreciated.