Created
December 30, 2018 13:53
-
-
Save yukin01/384b1b7cbc104f25acb4a051bf68fe4d to your computer and use it in GitHub Desktop.
Single to Taple in RxSwift
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
func synchronize<T>(_ single: Single<T>) -> (element: T?, error: Error?) { | |
var element: T? | |
var error: Error? | |
let condition = NSCondition() | |
condition.lock() | |
_ = single.subscribe({ event in | |
condition.lock() | |
switch event { | |
case .success(let elm): element = elm | |
case .error(let err): error = err | |
} | |
condition.signal() | |
condition.unlock() | |
}) | |
condition.wait() | |
condition.unlock() | |
return (element: element, error: error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment