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 theAPIRequest
has been completed. This function will not be called if an error has occurred, seeonError
handler for details on how to read out the error result.Note
The
APIRequest
will maintain an internal copy of the completed request data to handle the case that may occur if theonComplete
method is called after the request has already been completed.Declaration
Swift
@discardableResult public func onComplete(_ callback: @escaping (DataType) -> Void) -> Self
Parameters
callback
A closure that will be called when the
APIRequest
completes. -
Install a new callback into the
APIRequest
. This callback will be called when theAPIRequest
can’t be complete for one reason or another. TheHttpError
return indicates what type of error has occurred.Note
The
APIRequest
will maintain an internal copy of the any error that was signed before theonError
method was invoked, and willDeclaration
Swift
@discardableResult public func onError(_ callback: @escaping (RequestError) -> Void) -> Self
Parameters
callback
A closure that will be called if the
APIRequest
fails 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
APIRequest
Internally it modified the state of the APIRequest, so multiple calls will cause one thread to block indefinitely.Declaration
Swift
public func synchronousFetch() throws -> DataType