Google Apps Script has a 6 minute runtime limit, which can get frustrating when you're trying to do something complicated. To manage this limitation, I've written a short code snippet. It does the following:
If you want to use a similar approach in your own code, you're welcome to borrow as much or as little from the code below. Please remember to use the appropriate cache and properties service, as explained in the comments. Basically, if your script will only be run by one person, then the script properties & cache are fine. However, if you're using the same code in multiple documents, the document properties and cache would be more appropriate. Finally, if you're letting other users use your code, and you want to store information unique to each user, then you'd want to use the user properties and cache.
Apps Script >