Just like the title says, my problem is that humans are slow and interacting with them blocks the rest of my program. This problem doesn't really have to do with any one particular project, but is something that seems to come up for me all the time.
Let's say I'm have a program like this. I have a function that runs a really tight loop and does some really important stuff called importantFunction(). We can't allow that function to be blocked for more than a few milliseconds.
Now I want a function that allows the user to set the time. It has to ask sequentially for the month, day, year, hour, and minute and it can't block the importantFunction. So I'll make this function quick and make a pointer to this function and call it over and over again. One obvious solution is to have all of those answers as global variables and set them to -1 or something so I know where I am in the chain and each time through see where I am and check real quick if the user has entered anything yet. For just setting the time that sounds cool, but once my program has a lot of different things it can do, keeping up with all those globals becomes an issue.
But I don't see another option. If I wrote a blocking function I'd have month, day, year, hour, and minute as local to the function. They'd be in RAM on the stack but only while the function is alive. Then they're gone leaving space for the next thing that has to ask three or four questions in a row. But if I don't want to block I have to leave a whole bunch of globals around or use static variables and that's going to have the same memory issue. I also have to have a way to get this information back to the part of the program that was asking. I know how to use a callback, but again I have to leave all this information in a global place so it can be used by another function.
How is this supposed to work?