A way to wait for threads to complete using system.util. invokeAsynchronous?

an example splitting up system.tag.browse(). so if the loops executes 10 times and those threads are created, is there a way to wait for those threads to finish before continuing the code

global = system.tag.browse('Global')
for path in global:
----> system.util.invokeAsynchronous(task, [path])

def task(path):
----> folder = system.tag.browse(str(path['fullPath']), {'recursive' : True} )
---->print 'thread done'

1 Like

invokeAsynchronous() returns the java Thread object. You can use java's Thread.join() method to wait on that thread. However, do not do this in any foreground script--that defeats the entire point of using a background thread (and will lock up your UI).

Thanks for your response! It is not for a foreground script. I'll try it out.