Last active
July 1, 2022 20:03
-
-
Save cooler333/304e570da53415a02e336d68b913ea63 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 PlaygroundSupport | |
import Combine | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let queue = DispatchQueue(label: "some") | |
_ = Future<String, Never> { promise in | |
queue.asyncAfter(deadline: .now() + 2, execute: { | |
print(Thread.current) | |
promise(.success("TADA")) | |
}) | |
} | |
.subscribe(on: DispatchQueue.main) | |
.eraseToAnyPublisher() | |
.sink(receiveValue: { action in | |
print(action) | |
}) | |
_ = Future<String, Never> { promise in | |
queue.asyncAfter(deadline: .now() + 2, execute: { | |
print(Thread.current) | |
promise(.success("NE TADA")) | |
}) | |
} | |
.eraseToAnyPublisher() | |
.sink(receiveValue: { action in | |
print(action) | |
}) | |
print("Wait...") | |
/* | |
> Wait... | |
> <NSThread: 0x600001c011c0>{number = 6, name = (null)} | |
> TADA | |
> <NSThread: 0x600001c011c0>{number = 6, name = (null)} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment