Asynchronous alternative to gs.sleep()
Import
·
Aug 18, 2019
·
article
As gs.sleep() is undocumented, it is difficult to know quite how it works and if it ties up a thread unnecessarily (I suspect it does), so a good alternative if you're looking for an asynchronous wait server side is to use the schedule once script include (thanks to John Andersen for point this out).
gs.log('Started','Async example '+ Date.now());
var so = new ScheduleOnce();
so.script = "(function(){gs.log('I waited 5 seconds','Async example '+ Date.now())})()";
so.setAsSeconds(5);
so.schedule();
gs.log('Ended','Async example '+ Date.now());
View original source
https://www.servicenow.com/community/now-platform-articles/asynchronous-alternative-to-gs-sleep/ta-p/2320313