Finishing tasks before sleeping

Hello,

Let’s figure an applet stay-open performing in the background periodic records at a variable /Timing/


on Idle
  do_LengthyTasks()
  return Timing
end idle

The concern is the following:
Depending on the state of progress of the “lengthy tasks”, if the Mac is put to sleep, at next wake up randomly the applet can stay frozen instead of starting again its job.
Need to force to quit and relaunch the app.
I was guessing if using /considering and ignoring application responses/ could be of some utility, but couldn’t figure how?

Is there a trick to control this behaviour?
Thank you for the track, if any!