Skip to content

Instantly share code, notes, and snippets.

@soh335
Created April 20, 2016 02:55
Show Gist options
  • Save soh335/6200ecda4f99dda7f0e548db2e9c76eb to your computer and use it in GitHub Desktop.
Save soh335/6200ecda4f99dda7f0e548db2e9c76eb to your computer and use it in GitHub Desktop.
import Foundation
import RxSwift
let subject = RxSwift.PublishSubject<Int>()
let s = dispatch_semaphore_create(0)
Observable.zip(
subject.asObserver(), subject.asObserver().skip(1)
) { a, b in
return (a, b)
}.subscribe(
onNext: { (a, b) in
debugPrint(a, b)
},
onCompleted: {
dispatch_semaphore_signal(s)
}
)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
for i in 1...10 {
subject.onNext(i)
NSThread.sleepForTimeInterval(1)
}
subject.onCompleted()
})
dispatch_semaphore_wait(s, DISPATCH_TIME_FOREVER);
debugPrint("finish")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment