Skip to content

Commit 9143189

Browse files
committed
Add shouldBeTerminatedOnParentExit parameter to Task.launch
1 parent 05672c3 commit 9143189

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/Task.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,13 @@ extension Task {
390390
/// - Parameters:
391391
/// - standardInput: Data to stream to standard input of the launched process. If nil, stdin will
392392
/// be inherited from the parent process.
393+
/// - shouldBeTerminatedOnParentExit: A flag to control whether the launched child process should be terminated
394+
/// when the parent process exits. The default value is `false`.
393395
///
394396
/// - Returns: A producer that will launch the receiver when started, then send
395397
/// `TaskEvent`s as execution proceeds.
396-
public func launch(standardInput: SignalProducer<Data, NoError>? = nil) -> SignalProducer<TaskEvent<Data>, TaskError> {
398+
public func launch(standardInput: SignalProducer<Data, NoError>? = nil,
399+
shouldBeTerminatedOnParentExit: Bool = false) -> SignalProducer<TaskEvent<Data>, TaskError> {
397400
return SignalProducer { observer, lifetime in
398401
let queue = DispatchQueue(label: self.description, attributes: [])
399402
let group = Task.group
@@ -402,11 +405,13 @@ extension Task {
402405
process.launchPath = self.launchPath
403406
process.arguments = self.arguments
404407

405-
// This is for terminating subprocesses when the parent process exits.
406-
// See https://github.com/Carthage/ReactiveTask/issues/3 for the details.
407-
let selector = Selector(("setStartsNewProcessGroup:"))
408-
if process.responds(to: selector) {
409-
process.perform(selector, with: false as NSNumber)
408+
if shouldBeTerminatedOnParentExit {
409+
// This is for terminating subprocesses when the parent process exits.
410+
// See https://github.com/Carthage/ReactiveTask/issues/3 for the details.
411+
let selector = Selector(("setStartsNewProcessGroup:"))
412+
if process.responds(to: selector) {
413+
process.perform(selector, with: false as NSNumber)
414+
}
410415
}
411416

412417
if let cwd = self.workingDirectoryPath {

0 commit comments

Comments
 (0)