diff --git a/Sources/Task.swift b/Sources/Task.swift index 6bfaca1..685d5d6 100644 --- a/Sources/Task.swift +++ b/Sources/Task.swift @@ -390,10 +390,13 @@ extension Task { /// - Parameters: /// - standardInput: Data to stream to standard input of the launched process. If nil, stdin will /// be inherited from the parent process. + /// - shouldBeTerminatedOnParentExit: A flag to control whether the launched child process should be terminated + /// when the parent process exits. The default value is `false`. /// /// - Returns: A producer that will launch the receiver when started, then send /// `TaskEvent`s as execution proceeds. - public func launch(standardInput: SignalProducer? = nil) -> SignalProducer, TaskError> { + public func launch(standardInput: SignalProducer? = nil, + shouldBeTerminatedOnParentExit: Bool = false) -> SignalProducer, TaskError> { return SignalProducer { observer, lifetime in let queue = DispatchQueue(label: self.description, attributes: []) let group = Task.group @@ -402,11 +405,13 @@ extension Task { process.launchPath = self.launchPath process.arguments = self.arguments - // This is for terminating subprocesses when the parent process exits. - // See https://github.com/Carthage/ReactiveTask/issues/3 for the details. - let selector = Selector(("setStartsNewProcessGroup:")) - if process.responds(to: selector) { - process.perform(selector, with: false as NSNumber) + if shouldBeTerminatedOnParentExit { + // This is for terminating subprocesses when the parent process exits. + // See https://github.com/Carthage/ReactiveTask/issues/3 for the details. + let selector = Selector(("setStartsNewProcessGroup:")) + if process.responds(to: selector) { + process.perform(selector, with: false as NSNumber) + } } if let cwd = self.workingDirectoryPath {