Swiftpack.co - 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: 129
Help us keep the lights on

Used By

Total:

Releases

0.16.0 - Jun 13, 2019

Breaking

  • Updated to ReactiveSwift 5 (#112). It requires Swift 4.2 or above. Thanks @mattprowse!

Added

  • CocoaPods support (#111). Thanks @pepibumur!

Improved

  • Child processes should now terminate when the parent exits (#110). Thanks @ikesyo!

Fixed

  • Compilation on Linux (#109). Thanks @RahulKatariya!

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

0.15.0 - Aug 7, 2018

Breaking

  • Update ReactiveSwift to 4.0 (#107). So ReactiveTask now requires Xcode 9.4 (Swift 4.1). Thanks @ikesyo!

Improved

  • Utilize conditional conformances and synthesizing Equatable conformance (#108). Thanks @ikesyo!

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

0.14.0 - Nov 23, 2017

Breaking

  • ReactiveTask requires Xcode 9 (Swift 4) now (#100, #102, #103). Thanks @ikesyo!

Improved

  • Escape NULL terminator in strings with correct glyph (#104). Thanks @iv-mexx!
  • Update ReactiveSwift to 3.0 (#106). Thanks @ikesyo!

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

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.