stalbert
04/20/2018, 3:25 PMlazy.createSearch(...search criteria for delete)
.takewhile(governanceRemains)
.each(... do stuff)
and the function governanceRemains just checks that say 200 units remain and if not it reschedules the script and returns false. This provides a very clean exit and works with an arbitrarily large number of search results.