Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carthage/reactivetask
Flexible, stream-based abstraction for launching processes
https://github.com/carthage/reactivetask
reactiveswift swift
Last synced: 9 days ago
JSON representation
Flexible, stream-based abstraction for launching processes
- Host: GitHub
- URL: https://github.com/carthage/reactivetask
- Owner: Carthage
- License: mit
- Created: 2014-12-01T22:01:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T07:52:23.000Z (about 5 years ago)
- Last Synced: 2024-05-13T14:46:59.080Z (6 months ago)
- Topics: reactiveswift, swift
- Language: Swift
- Homepage:
- Size: 305 KB
- Stars: 132
- Watchers: 13
- Forks: 26
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ReactiveTask
ReactiveTask is a Swift framework for launching shell tasks (processes), built using [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift).```swift
let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ]
let input = SignalProducer(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? = 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](https://github.com/Carthage/Carthage) framework.
## License
ReactiveTask is released under the [MIT license](LICENSE.md).