RxSwiftCommunity/RxTask

Name: RxTask

Owner: RxSwift Community

Description: An RxSwift implementation of a command line runner.

Created: 2017-02-16 00:59:08.0

Updated: 2017-10-30 03:52:36.0

Pushed: 2017-02-28 16:37:47.0

Homepage: null

Size: 567

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

RxTask

An RxSwift implementation of a command line task runner.

GitHub release Build Status codecov docs carthage compatible swift package manager compatible platform macOS language swift 3.0

Linux Compatibility

Currently, RxTask does not support Linux. RxTask relies on some functionality in Foundation that is currently not available in the Linux port. This will be re-evaluated after the Swift 3.1 release. PRs in this area are quite welcome! ?

Installation
Carthage
ub "RxSwiftCommunity/RxTask"
SPM
rt PackageDescription

package = Package(
name: "YOUR_PROJECT_NAME",
targets: [],
dependencies: [
    .Package(url: "https://github.com/RxSwiftCommunity/RxSwift.git", majorVersion: 0)
]

Usage
Create A Task

Creating a task is as simple as providing a launchPath to the executable.

task = Task(launchPath: "/bin/ls")

Optionally, you can provide arguments, a workingDirectory, and an environment.

task = Task(launchPath: "/bin/echo", arguments: ["$MESSAGE"], environment: ["MESSAGE": "Hello World!"])
Launch A Task

Tasks can be launched with the launch() method. This produces a self-contained process. This means the same task can be launch()ed multiple times producing separate processes.

TaskEvent

The output of launch() is a Observable<TaskEvent>. TaskEvent is an enum that is used to report significant events in the task lifetime. The possible events are:

Note: Currently an event is only considered successful if it exits with a statusCode of 0. Other exit statuses will be considered a TaskError.

StdIn

If you create a task that expects input, you can provide an Observable<Data> for stdin when you are launch()ing the Task. Data will be written to stdin as soon as it is emitted by the Observable.

Filtering TaskEvents

If you are only concerned with whether a Task has completed successfully, you can use the built-in operator justExitStatus().

(launchPath: "/bin/ls").launch()
.justExitStatus()
.subscribe(onNext: { exitStatus in /* ... */ })
.disposed(by: disposeBag)

Alternatively, if you are only interested in the output of a Task, you can use the operator justOutput(). This will send the output of both stdout and stderr.

(launchPath: "/bin/ls").launch()
.justOutput()
.subscribe(onNext: { output in /* ... */ })
.disposed(by: disposeBag)
TaskError

TaskError is an Error that will be emitted under the following situations:

API Reference

Full docs can be found here.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.