Last active
September 1, 2020 12:01
-
-
Save haifengkao/da9ff614518976f374186028d8361ee6 to your computer and use it in GitHub Desktop.
combineLatest test
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
import Cocoa | |
import Combine | |
var subscriptions = Set<AnyCancellable>() | |
func futureIncrement( | |
integer: Int, | |
afterDelay delay: TimeInterval) -> AnyPublisher<Int, Never> { | |
Deferred { | |
Future<Int, Never> { promise in | |
print("init") | |
promise(.success(integer + 1)) | |
} | |
}.subscribe(on: DispatchQueue.main).eraseToAnyPublisher() | |
} | |
let future = futureIncrement(integer: 1, afterDelay: 3) | |
future | |
.sink(receiveCompletion: { print($0) }, | |
receiveValue: { print($0) }) | |
.store(in: &subscriptions) | |
future | |
.sink(receiveCompletion: { print("Second", $0) }, | |
receiveValue: { print("Second", $0) }) | |
.store(in: &subscriptions) | |
Just(2).combineLatest(future).sink(receiveCompletion: { print("you won't see me", $0) }, | |
receiveValue: { print("never 1", $0) }) | |
.store(in: &subscriptions) | |
future.combineLatest(Just(2)).sink(receiveCompletion: { print("you won't see me, too", $0) }, | |
receiveValue: { print("never 2", $0) }) | |
.store(in: &subscriptions) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
這樣寫也不會動,我覺得這是bug