Created
September 30, 2021 06:08
-
-
Save atsukoba/4db00d701c493850fd4f0e534de802a4 to your computer and use it in GitHub Desktop.
Synchronized request sending with APIKit in Swift5
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 APIKit | |
extension Session { | |
open class func sendSync<T: Request>(_ request: T) -> Result<T.Response, SessionTaskError> { | |
var result: Result<T.Response, SessionTaskError>! | |
let semaphor = DispatchSemaphore(value: 0) | |
self.send(request, callbackQueue: .sessionQueue) { _result in | |
result = _result | |
semaphor.signal() | |
} | |
semaphor.wait() | |
return result | |
} | |
} |
Author
atsukoba
commented
Sep 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment