Skip to content

Instantly share code, notes, and snippets.

@cooler333
Last active July 1, 2022 20:03
Show Gist options
  • Save cooler333/304e570da53415a02e336d68b913ea63 to your computer and use it in GitHub Desktop.
Save cooler333/304e570da53415a02e336d68b913ea63 to your computer and use it in GitHub Desktop.
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