FunctionCallable

@dynamicCallable
public struct FunctionCallable : Sendable

为用户函数启用以下语法糖的结构:

guard case let .int32(sum) = try await user.functions.sum([1, 2, 3, 4, 5]) else {
   return
}

动态成员名称(上例中为sum )由与函数名称直接关联的@dynamicMemberLookup提供。

  • 允许Future<AnyBSON, Error>可调用返回的 @DynamicCallable 实现。

    let cancellable = user.functions.sum(1, 2, 3, 4, 5)
       .sink(receiveCompletion: { result in
    }, receiveValue: { value in
       // Returned value from function
    })
    

    声明

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func dynamicallyCall(withArguments args: [AnyBSON]) -> Future<AnyBSON, Error>
  • dynamicallyCall(withArguments:) 异步(Asynchronous)

    允许async await可调用返回的 @DynamicMemberLookup 的实施。

    guard case let .int32(sum) = try await user.functions.sum(1, 2, 3, 4, 5) else {
       return
    }
    

    声明

    Swift

    public func dynamicallyCall(withArguments args: [AnyBSON]) async throws -> AnyBSON