Let's say, for example, that my target framerate is 60 frames per second.
Now, I know that I have a maximum of 16.6 milliseconds to "do everything" every frame in order to maintain that framerate.
Let's say that I also have a background task that I wish to run. It will return some results. I don't need them urgently; I just wish to run it and have its results when it's done.
Here's my point. I know when I'm done rendering everything;
WaitForEndOfFrame() in a coroutine tells me so. Let's say my last frame took only 13 milliseconds to render instead of 16.6, so I know I have 3.6 milliseconds to spare during which I would like to run my task for exactly those 3.6 miliseconds or less, never going over my 16.6 milliseconds maximum total, and then continue with the next frame, on which I will do the same if I get some spare time.
Could I achieve this using Unity's coroutines (or some other way)? If so, how?