Waiting for asynchronous calls in a swift script
In addition to using dispatch_groups
, you can also do the following:
yourAsyncTask(completion: {
exit(0)
})
RunLoop.main.run()
Some resources:
- RunLoop docs
- Example from the swift-sh project
- Exit code meanings
Thanks to Aaron Brager, who linked to Multiple workers in Swift Command Line Tool ,
which is what I used to find my answer, using dispatch_groups to solve the problem.