Skip to content

Commit 827174c

Browse files
committed
Move standardInput to launchTask
1 parent 545496f commit 827174c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

ReactiveTask/Task.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,11 @@ public struct Task {
3030
/// If nil, the launched task will inherit the environment of its parent.
3131
public var environment: [String: String]?
3232

33-
/// Data to stream to standard input of the launched process.
34-
///
35-
/// If nil, stdin will be inherited from the parent process.
36-
public var standardInput: SignalProducer<NSData, NoError>?
37-
38-
public init(_ launchPath: String, arguments: [String] = [], workingDirectoryPath: String? = nil, environment: [String: String]? = nil, standardInput: SignalProducer<NSData, NoError>? = nil) {
33+
public init(_ launchPath: String, arguments: [String] = [], workingDirectoryPath: String? = nil, environment: [String: String]? = nil) {
3934
self.launchPath = launchPath
4035
self.arguments = arguments
4136
self.workingDirectoryPath = workingDirectoryPath
4237
self.environment = environment
43-
self.standardInput = standardInput
4438
}
4539

4640
/// A GCD group which to wait completion
@@ -389,11 +383,15 @@ extension Signal where Value: TaskEventType {
389383
}
390384
}
391385

392-
/// Launches a new shell task, using the parameters from `taskDescription`.
386+
/// Launches a new shell task.
387+
///
388+
/// taskDescription - The task to launch.
389+
/// standardInput - Data to stream to standard input of the launched process. If nil, stdin will
390+
/// be inherited from the parent process.
393391
///
394392
/// Returns a producer that will launch the task when started, then send
395393
/// `TaskEvent`s as execution proceeds.
396-
public func launchTask(taskDescription: Task) -> SignalProducer<TaskEvent<NSData>, TaskError> {
394+
public func launchTask(taskDescription: Task, standardInput: SignalProducer<NSData, NoError>? = nil) -> SignalProducer<TaskEvent<NSData>, TaskError> {
397395
return SignalProducer { observer, disposable in
398396
let queue = dispatch_queue_create(taskDescription.description, DISPATCH_QUEUE_SERIAL)
399397
let group = Task.group
@@ -412,7 +410,7 @@ public func launchTask(taskDescription: Task) -> SignalProducer<TaskEvent<NSData
412410

413411
var stdinProducer: SignalProducer<(), TaskError> = .empty
414412

415-
if let input = taskDescription.standardInput {
413+
if let input = standardInput {
416414
switch Pipe.create(queue, group) {
417415
case let .Success(pipe):
418416
task.standardInput = pipe.readHandle

ReactiveTaskTests/TaskSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TaskSpec: QuickSpec {
6161
let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ]
6262
let data = strings.map { $0.dataUsingEncoding(NSUTF8StringEncoding)! }
6363

64-
let result = launchTask(Task("/usr/bin/sort", standardInput: SignalProducer(values: data)))
64+
let result = launchTask(Task("/usr/bin/sort"), standardInput: SignalProducer(values: data))
6565
.map { event in event.value }
6666
.ignoreNil()
6767
.single()

0 commit comments

Comments
 (0)