Skip to content

Commit

Permalink
Add shouldBeTerminatedOnParentExit parameter to Task.launch
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Sep 25, 2018
1 parent 05672c3 commit 9143189
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Sources/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data, NoError>? = nil) -> SignalProducer<TaskEvent<Data>, TaskError> {
public func launch(standardInput: SignalProducer<Data, NoError>? = nil,
shouldBeTerminatedOnParentExit: Bool = false) -> SignalProducer<TaskEvent<Data>, TaskError> {
return SignalProducer { observer, lifetime in
let queue = DispatchQueue(label: self.description, attributes: [])
let group = Task.group
Expand All @@ -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 {
Expand Down

0 comments on commit 9143189

Please sign in to comment.