The ideal thing to do here is to pre-empt the range of identifiers getting exhausted. Say you have range of 1 to 1024, the code detects when .generate() has issued 1000 and query the generator for the next range.
To avoid the current thread getting delayed in getting the next range from a datastore a new short lived thread executes the work then dies.
|