2019-12-18a few seconds read (About 106 words)How to keep command line tool running with async in SwiftIssue #549 Use Semaphore123456789101112131415161718192021222324252627282930313233public class Sequence: Task { public func run(workflow: Workflow, completion: @escaping TaskCompletion) { let semaphore = DispatchSemaphore(value: 0) runFirst(tasks: tasks, workflow: workflow, completion: { result in completion(result) semaphore.signal() }) semaphore.wait() }}public class Concurrent: Task { public func run(workflow: Workflow, completion: @escaping (Result<(), Error>) -> Void) { var runTaskCount = 0 let taskCount = tasks.count let semaphore = DispatchSemaphore(value: 0) tasks.forEach { task in task.run(workflow: workflow, completion: { _ in self.serialQueue.async { runTaskCount += 1 if runTaskCount == taskCount { completion(.success(())) semaphore.signal() } } }) } semaphore.wait() }} Read more https://stackoverflow.com/questions/31944011/how-to-prevent-a-command-line-tool-from-exiting-before-asynchronous-operation-co #swiftterminal