Created
June 15, 2019 14:33
-
-
Save jrsonline/3a2346c423edf0649182fe6211673d08 to your computer and use it in GitHub Desktop.
Sample using toBlockingArray ... and a way to publish debug output!
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
struct NSLoggerStream : TextOutputStream { | |
mutating func write(_ string: String) { | |
guard string.count > 0 && string != "\n" else { return } | |
NSLog(string) | |
} | |
} | |
// Test | |
var logger = NSLoggerStream() | |
let result = Publishers.Future<Int,TestError> { subscriber in | |
DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + .seconds(2)) { | |
subscriber(.success(42)) | |
// subscriber(.failure(TestError() )) // <== try swapping the success and failure | |
} | |
} | |
.print("[Test Publish/Subscribe]", to: logger ) | |
.toBlockingResult(timeout: 5) <== try changing the timeout to 1 second | |
.map { $0.last! } | |
print("Result is \(result)", to: &logger) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment