QueryResult
public class QueryResult<T>
Represent the result of an asynchronous query executed by FaunaDB.
Note
All methods available to handleQueryResult success or failure
will optionally receive a DispatchQueue. Remember, the only
DispatchQueue allowed to update the UI is DispatchQueue.main.
-
Maps the result returned by the server using the function provided.
Declaration
Swift
public func map<A>(at queue: DispatchQueue? = nil, _ transform: @escaping (T) throws -> A) -> QueryResult<A>Parameters
queueThe dispatch queue in which the transformation will be performed.
transformThe transformation to be applied on the result value.
Return Value
A
QueryResultcontaining the transformed value. -
Flat maps the result returned by the server using the function provided.
Declaration
Swift
public func flatMap<A>(at queue: DispatchQueue? = nil, _ transform: @escaping (T) throws -> QueryResult<A>) -> QueryResult<A>Parameters
queueThe dispatch queue in which the transformation will be performed.
transformThe transformation to be applied on the result value.
Return Value
A
QueryResultcontaining the transformed value.
-
Apply a transformation if an error has occurred during the query execution.
If
mapErrreturns a value, the resultingQueryResultwill be transformed into a success result. If you wish to handle an error but still return a failingQueryResult, you must rethrow an exception.For example:
// Revover from an error client.query(/* some queryDeclaration
Swift
public func mapErr(at queue: DispatchQueue? = nil, _ transform: @escaping (Error) throws -> T) -> QueryResultParameters
queuetransform -
Apply a transformation if an error has occurred during the query execution.
If
flatMapErrreturns a value, the resultingQueryResultwill be transformed into a success result. If you wish to handle an error but still return a failingQueryResult, you must rethrow an exception.For example:
// Revover from an error client.query(/* some queryDeclaration
Swift
public func flatMapErr(at queue: DispatchQueue? = nil, _ transform: @escaping (Error) throws -> QueryResult) -> QueryResultParameters
queuetransform
-
Execute the provided callback when the resulting
QueryResultis successful.Declaration
Swift
public func onSuccess(at queue: DispatchQueue? = nil, _ callback: @escaping (T) throws -> Void) -> QueryResultParameters
queueThe dispatch queue in which the callback will be executed.
callbackThe callback to be called when the resulting value is available.
-
Execute the provided callback when an error occurs during the query execution.
Declaration
Swift
public func onFailure(at queue: DispatchQueue? = nil, _ callback: @escaping (Error) throws -> Void) -> QueryResultParameters
queueThe dispatch queue in which the callback will be executed.
callbackThe callback to be called when an error occurs.
-
Blocks the current thread, waiting for the query to be executed.
Note
This method is discouraged due to its blocking nature. Prefer
map,onSuccess, and their variations to prevent your code from blocking your application.Throws
Any exception that might have happened during the query execution.
Declaration
Swift
public func await(timeout: DispatchTime) throws -> TParameters
timeoutHow long it should wait for the result to come back.
Return Value
The resulting query value.
QueryResult Class Reference