Package - Carthage/ReactiveTask

ReactiveTask

ReactiveTask is a Swift framework for launching shell tasks (processes), built using ReactiveSwift.

let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ]
let input = SignalProducer<Data, NoError>(values: strings.map { $0.data(using: .utf8)! })
let task = Task("/usr/bin/sort")

// Run the task, ignoring the output, and do something with the final result.
let result: Result<String, TaskError>? = task.launch(standardInput: input)
    .ignoreTaskData()
    .map { String(data: $0, encoding: .utf8) }
    .ignoreNil()
    .single()
print("Output of `\(task)`: \(result?.value ?? "")")

// Start the task and print all the events, which includes all the output
// that was received.
task.launch(standardInput: input)
    .flatMapTaskEvents(.concat) { data in
        return SignalProducer(value: String(data: data, encoding: .utf8))
    }
    .startWithNext { (event: TaskEvent) in
        switch event {
        case let .launch(task):
            print("launched task: \(task)")

        case let .standardError(data):
            print("stderr: \(data)")

        case let .standardOutput(data):
            print("stdout: \(data)")

        case let .success(string):
            print("value: \(string ?? "")")
        }
    }

For examples of how to use ReactiveTask, see the Xcode and Git integration code from the CarthageKit framework.

License

ReactiveTask is released under the MIT license.

Github

link
Stars: 121

Advertisement

Releases

0.13.0 - Jul 25, 2017

Improved

  • Update ReactiveSwift to 2.0 (#97, #98, #99). Thanks @ikesyo!

Thank you to @mdiep for reviewing pull requests.

0.12.0 - Jul 4, 2017

Breaking

  • ReactiveTask requires Xcode 8.3 (Swift 3.1) now (#94). Thanks @ikesyo!

Improved

  • The working directory is added to Task.description if set (#95). Thanks @ikesyo!

Thank you to @mdiep for reviewing pull requests.

0.11.1 - Mar 28, 2017

Improved

  • Update dependencies (#89, #91, #92). Thanks @ikesyo!
  • Swift Package Manager interoperability with other dependencies (#90). Thanks @ikesyo!
  • Task.description now correctly escape whitespace characters included in its arguments instead of quoting the entire argument (#93). Thanks @ikesyo!

Thank you to @mdiep and @NachoSoto for reviewing pull requests.

0.11.0 - Feb 1, 2017

Added

  • Swift 3 support (#62, #72, #80). Thanks @mattprowse and @ikesyo!
  • Support for Swift Package Manager (#88). Thanks @ikesyo!

Improved

  • launchTask is now Task.launch (#76). Thanks @ikesyo!

Thank you to @ikesyo and @mdiep for improvements to the codebase. Thank you to @mdiep, @NachoSoto, and @ikesyo for reviewing pull requests.

0.10.3 - Jul 20, 2016

Added

  • Support for Swift 2.3 and Xcode 8 (#69). Thanks @ikesyo!

Thank you to @mdiep for reviewing pull requests!