Created
December 2, 2016 20:27
-
-
Save mminer/ddfb1df186f45f5324ffd95e96570377 to your computer and use it in GitHub Desktop.
SocketIOClient extension to subscribe to events via RxSwift observable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import SocketIO | |
extension Reactive where Base: SocketIOClient { | |
public func on(_ event: String) -> Observable<[Any]> { | |
return Observable.create { observer in | |
let id = self.base.on(event) { items, _ in | |
observer.onNext(items) | |
} | |
return Disposables.create { | |
self.base.off(id: id) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment