Skip to content

An RxSwift extension for converting callbacks to observables.

License

Notifications You must be signed in to change notification settings

BrianSemiglia/RxCallbacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RxCallbacks

CI Status Version License Platform

Usage

// Function with single argument of completion handler
let x: Observable<Void> = .fromCallback(PHPhotoLibrary.shared().performChangesAndWait)
    
// Function with n arguments, the last being a completion handler
let y: Observable<(Bool, Error?)> = .fromCallback(curry(PHPhotoLibrary.shared().performChanges)({ /* changes */ }))

// Functions that accept completion handlers AND return non-void types aren't compatible ❌
let z: Observable<Void> = .fromCallback(curry(URLSession.shared().dataTask)(URL(string: "")!))

// Because some functions produce multiple callbacks, the Observable returned by `.fromCallback`
// intentionally avoids producing a completion event. To achieve this, the caller may use the 
// `take` operator to produce this event.
let n = Observable<PartialData>.fromCallback(Network.progressiveDownload).take(3)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

RxCallbacks is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxCallbacks'

Author

brian.semiglia@gmail.com

License

RxCallbacks is available under the MIT license. See the LICENSE file for more info.

About

An RxSwift extension for converting callbacks to observables.

Resources

License

Stars

Watchers

Forks

Packages

No packages published