Flexible, stream-based abstraction for launching processes

Overview

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.

Comments
  • Add waitForAllTaskTermination for fixing segmentation fault of Carthage

    Add waitForAllTaskTermination for fixing segmentation fault of Carthage

    This is rebased version of #21.

    Fix segmentation fault on termination of Carthage.

    Segmentation fault on termination of Carthage 0.7.4 beta-2 happens following scenario:

    1. launchTask's thread call sendCompleted() and kick main thread 2a. main thread wake up and call exit() 2b. launchTask's thread continue disposing
    2. main thread cause segmentation fault.

    Waiting completed from launchTask's thread is not enough for fixing the segmentation fault. It needs waiting actual termination of launchTask's thread

    https://github.com/Carthage/Carthage/pull/474#issuecomment-107949958

    opened by norio-nomura 9
  • Swift 3 Support

    Swift 3 Support

    Moves ReactiveTask to Swift 3, targeting Xcode 8 beta 1. I'll keep the PR updated as each new beta appears.

    • Currently uses ReactiveCocoa's RAC5-swift3 branch, and the same targets as RAC for Quick, Nimble, and Result.
    • The deployment target had to be raised to 10.10 to match ReactiveCocoa.
    • All tests pass except "should launch a task with standard input", which crashes on run. I'll figure out why and update the PR with a fix if possible.
    • The only major changes made to the ReactiveTask API are the lowercasing of all enum cases as per the Swift 3 API guidelines, and the replacement of NSData with Data.
    opened by mattprowse 8
  • Replace incremental data sinks with a single stream of TaskEvent enums

    Replace incremental data sinks with a single stream of TaskEvent enums

    ~~Depends on #22.~~

    This is a refactoring that should've been done when we first moved from ColdSignal + HotSignal to SignalProducer + Signal.

    The current sink-focused implementation bifurcates logic, and makes it really easy to introduce issues like that fixed by https://github.com/Carthage/ReactiveTask/pull/21. Handling everything within the same stream should make behavior more deterministic.

    opened by jspahrsummers 5
  • Add CocoaPods support

    Add CocoaPods support

    I'd like to use ReactiveTask from a library for which I'd like to provide CocoaPods and Carthage support. Unfortunately, ReactiveTask doesn't support doesn't have support for CocoaPods.

    I've created a .podspec file that can be used to publish ReactiveTask on CocoaPods.

    opened by pepicrft 4
  • [WIP] Swift 2.2 Support

    [WIP] Swift 2.2 Support

    Update dependencies for Xcode 7.3/Swift 2.2. Replace TaskEventType's use of typealias with associatetype.

    I'm expecting this to remain WIP until there are Swift 2.2 releases of ReactiveCocoa and Quick.

    opened by mattprowse 3
  • Escape NULL terminator in strings with correct glyph

    Escape NULL terminator in strings with correct glyph

    As discussed in https://github.com/Carthage/Carthage/pull/2252#issuecomment-344060192

    Two questions:

    • The function is currently called escapingWhitespaces. Should we rename it or could NULL be considered a Whitespace?
    • I've used the glyph directly (␀) - is this fine or is it better to use the unicode codepoint? (U+2400)?

    @jdhealy

    opened by iv-mexx 2
  • Simplify some naming

    Simplify some naming

    I really dislike some of the current naming in ReactiveTask. This PR cleans that up and makes a few more breaking changes while I'm at it:

    • Rename TaskDescription to Task
    • Remove the launchPath: parameter name from Task.init
    • Rename ReactiveTaskError to TaskError
    • Move standardInput from Task to launchTask
    • Make Task conform to Hashable
    • Add a Launch case to TaskEvent that sends the Task

    The latter 3 changes were motivated by a desire to print executed commands in Carthage. Right now, we only print the output of commands. It'd be nice to print the commands themselves.

    opened by mdiep 2
  • Better Readme

    Better Readme

    The README.md is a little bit confusing. I created this iOS Open source Readme Template so you can take a look on how to better organize. If you want, I can help you to organize the README.md.

    What are your thoughts?

    opened by lfarah 1
Releases(0.16.0)
Owner
Carthage
A simple, decentralized dependency manager for Cocoa
Carthage
A configurable api client based on Alamofire4 and RxSwift4 for iOS

SimpleApiClient A configurable api client based on Alamofire4 and RxSwift4 for iOS Requirements iOS 8.0+ Swift 4 Table of Contents Basic Usage Unwrap

Jay 67 Dec 7, 2020
🎌 Powerful navigation library for iOS based on the coordinator pattern

⚠️ We have recently released XCoordinator 2.0. Make sure to read this section before migrating. In general, please replace all AnyRouter by either Uno

QuickBird Studios 2k Dec 30, 2022
Monitor and terminate/throttle CPU hogging processes in iOS

Vedette Monitor and terminate/throttle CPU hogging processes in iOS Vedette is a CPU usage monitoring tweak for processes in iOS like apps and daemons

null 13 Dec 22, 2022
Check for suspicious processes on macOS.

pschk Check for suspicious processes on macOS. Installation $ make $ sudo make install or $ brew tap x13a/tap $ brew install x13a/tap/pschk Usage USAG

lucky 3 Sep 3, 2022
Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Launch Navigator Cordova/Phonegap Plugin Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

null 0 Oct 25, 2021
A Simple exemple of a launching screen made of 100% using SwuiftUI.

A Simple exemple of a launching screen made of 100% using SwuiftUI. You can modify and use it in your app Compatible from iOS 14 (older not tested ) to iOS 16 (beta tested only )

Maxime 2 Nov 4, 2022
A SwiftUI component for launching custom picture-in-picture experiences

Pipify for SwiftUI This library introduces a new SwiftUI modifier that enables a view to be shown within a Picture in Picture overlay. This overlay al

Sidetrack 99 Dec 16, 2022
▶️ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Jan 2, 2023
▶️ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Dec 24, 2022
A library for creating Stream Deck plugins in Swift.

StreamDeck A library for creating Stream Deck plugins in Swift. Usage Your plugin class should inherit from StreamDeckPlugin, which handles the WebSoc

Emory Dunn 15 Jan 2, 2023
Official SwiftUI SDK for Stream Chat.

SwiftUI - Currently in Development ?? The SwiftUI SDK is built on top of the StreamChat framework and it's a SwiftUI alternative to the StreamChatUI S

Stream 136 Dec 23, 2022
Prototyping Stream Chat iOS SDK with SwiftUI.

Prototyping Stream Chat iOS SDK with SwiftUI.This project includes layout and composition of the main screens such as the channel list (contacts), select user and chats (conversations). Additionally there are several SwiftUI animations along with interaction styles.

Stream 9 Jan 8, 2023
Phiole - Allow to write or read from standards stream or files for script or CLI application

No longer maintained! Phiole - Φole Simple object to wrap three NSFileHandle: 'output', 'error' to write and 'input' to read There is of course a defa

Eric Marchand 8 Sep 10, 2018
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

Daniel Kennett 77 Dec 27, 2022
DelayStream - A swift version to stream a file or stdin one line at a time with a delay

DelayStream A swift version to stream a file or stdin one line at a time with a

Keanu Pang 0 Jan 28, 2022
Ios-desde-cero - Code, documents and resources used in the Stream iOS from scratch

iOS desde cero ¿Qué es esto? iOS desde Cero es un Streaming en ???? sobre desarr

Diego Freniche 36 Aug 22, 2022
SwiftUI iOS app which applies CoreML Video Matting (background removal) model to the front camera stream

CoreML Camera Video Matting This is a simple iOS app which applies Video Matting (background removal) model to the front camera stream. Video Matting

Dmitry Voitekh 17 Dec 29, 2022
🛶Shallows is a generic abstraction layer over lightweight data storage and persistence.

Shallows Shallows is a generic abstraction layer over lightweight data storage and persistence. It provides a Storage<Key, Value> type, instances of w

Oleg Dreyman 620 Dec 3, 2022
Rx is a generic abstraction of computation expressed through Observable Element interface,

Rx is a generic abstraction of computation expressed through Observable<Element> interface, which lets you broadcast and subscribe to values and other events from an Observable stream.

ReactiveX 23.1k Dec 31, 2022
Type-safe networking abstraction layer that associates request type with response type.

APIKit APIKit is a type-safe networking abstraction layer that associates request type with response type. // SearchRepositoriesRequest conforms to Re

Yosuke Ishikawa 1.9k Dec 30, 2022