Functions
@dynamicMemberLookup
@frozen
public struct Functions : Sendable
Structure providing an interface to call an Atlas App Services function with the provided name and arguments.
user.functions.sum([1, 2, 3, 4, 5]) { sum, error in
guard case let .int64(value) = sum else {
print(error?.localizedDescription)
}
assert(value == 15)
}
The dynamic member name (sum
in the above example) is directly associated with the function name.
The first argument is the BSONArray
of arguments to be provided to the function.
The second and final argument is the completion handler to call when the function call is complete.
This handler is executed on a non-main global DispatchQueue
.
-
A closure type for receiving the completion of a remote function call.
Declaration
Swift
public typealias FunctionCompletionHandler = @Sendable (AnyBSON?, Error?) -> Void
-
A closure type for the dynamic remote function type.
Declaration
Swift
public typealias Function = @Sendable ([AnyBSON], @escaping FunctionCompletionHandler) -> Void
-
The implementation of @dynamicMemberLookup that allows for dynamic remote function calls.
Declaration
Swift
public subscript(dynamicMember string: String) -> Function { get }
-
A closure type for receiving the completion result of a remote function call.
Declaration
Swift
public typealias ResultFunctionCompletionHandler = @Sendable (Result<AnyBSON, Error>) -> Void
-
A closure type for the dynamic remote function type.
Declaration
Swift
public typealias ResultFunction = @Sendable ([AnyBSON], @escaping ResultFunctionCompletionHandler) -> Void
-
The implementation of @dynamicMemberLookup that allows for dynamic remote function calls with a
ResultFunctionCompletionHandler
completion.Declaration
Swift
@preconcurrency public subscript(dynamicMember string: String) -> ResultFunction { get }
-
The implementation of @dynamicMemberLookup that allows for dynamic remote function calls with a
callable
return.Declaration
Swift
public subscript(dynamicMember string: String) -> FunctionCallable { get }