APIRequest
public class APIRequest<DataType>
An APIRequest is a class that is used to capture an asynchronous result
from a HTTP request. This class will be called by the SDK when the result
has completed, and acts as a way to communicate the data back to the client
logic.
Note
Internally APIRequest will capture the state of the request if the SDK client
did not install a callback in-time. This avoid any race with the asynchronous
request.
Note
All callbacks will always be invoked on the main application thread.
-
Install a new callback into the
APIRequest. This callback will be called when theAPIRequesthas been completed. This function will not be called if an error has occurred, seeonErrorhandler for details on how to read out the error result.Note
The
APIRequestwill maintain an internal copy of the completed request data to handle the case that may occur if theonCompletemethod is called after the request has already been completed.Declaration
Swift
@discardableResult public func onComplete(_ callback: @escaping (DataType) -> Void) -> SelfParameters
callbackA closure that will be called when the
APIRequestcompletes. -
Install a new callback into the
APIRequest. This callback will be called when theAPIRequestcan’t be complete for one reason or another. TheHttpErrorreturn indicates what type of error has occurred.Note
The
APIRequestwill maintain an internal copy of the any error that was signed before theonErrormethod was invoked, and willDeclaration
Swift
@discardableResult public func onError(_ callback: @escaping (RequestError) -> Void) -> SelfParameters
callbackA closure that will be called if the
APIRequestfails to complete. -
By blocking the current thread, fetch the any pending tasks.
if an Error occurred, this function will throw the error.
Note: Only one thread may call this function on a single
APIRequestInternally it modified the state of the APIRequest, so multiple calls will cause one thread to block indefinitely.Declaration
Swift
public func synchronousFetch() throws -> DataType
View on GitHub
APIRequest Class Reference