Let's say I want to execute a block of code later in time, so I call dispatch_after
like so:
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
/* code */
});
But what if I want to "pause" my program before the execution even began? Let's say I want to pause the program 1 second after this call for unknown time. Then after the pause, I would like to resume the 2 second waiting on the queue. So it would look something like this:
- call dispatch_after with a 2 second delay
- after 1 second, pause the program for unknown time
- after resuming, wait 1 second and execute the block (so the total delay is 2 secs)
Is there a way of doing that? Or should I use another approach?
I know that dispatch_suspend
and dispatch_resume
exist, but they don't really work for me (or I just don't know how to use them properly).
The solution doesn't necessarily have to involve a block, it could also be a delayed callback to a specified function. The point is that I want to be able to pause the waiting time until execution.