Last active
September 18, 2017 21:31
-
-
Save xandrefreire/62af2b8121dca1db9c9e0a017de47c40 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// anwswer to http://stackoverflow.com/questions/41915285/polling-with-rxswift-and-parse-server | |
func myObs() -> Observable<Int> { | |
return Observable<Int>.create { observer in | |
let sig = Observable<Int>.interval(1.0, scheduler: MainScheduler.instance) | |
let subscription = | |
sig.subscribe(onNext: { num in | |
observer.onNext(num) | |
if num == 10 { | |
observer.onCompleted() | |
} | |
}) | |
return Disposables.create { | |
subscription.dispose() | |
} | |
} | |
} | |
let _ = myObs().subscribe(onNext: {num in | |
print(num) | |
}) | |
// OUTPUT | |
// 0 | |
// 1 | |
// 2 | |
// 3 | |
// 4 | |
// 5 | |
// 6 | |
// 7 | |
// 8 | |
// 9 | |
// 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment