Skip to content

Instantly share code, notes, and snippets.

@yukin01
Created December 30, 2018 13:53
Show Gist options
  • Save yukin01/384b1b7cbc104f25acb4a051bf68fe4d to your computer and use it in GitHub Desktop.
Save yukin01/384b1b7cbc104f25acb4a051bf68fe4d to your computer and use it in GitHub Desktop.
Single to Taple in RxSwift
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