Created
April 20, 2016 02:55
-
-
Save soh335/6200ecda4f99dda7f0e548db2e9c76eb to your computer and use it in GitHub Desktop.
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 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