Skip to content

Add async/await support #332

@aronbudinszky

Description

@aronbudinszky

Description
Since server-side Swift projects like Vapor now support async/await APIs, it would nice if meilisearch-swift also added this.

Basic example
As opposed to the completion parameter style currently used, an async/await call would look like so:

let result = await index.updateDocuments(documents: [/** data **/], primaryKey: "id")
switch result {
case .success:
    // ....
case .failure(let error):
    // ....
}

Proposed solution
I have already created extensions in my local project to support some of the methods that I use. For example updateDocuments() is covered by this implementation:

public func updateDocuments<T>(
  documents: [T],
  encoder: JSONEncoder? = nil,
  primaryKey: String? = nil) async -> Result<TaskInfo, Swift.Error> where T: Encodable {
      return await withCheckedContinuation { continuation in
          self.updateDocuments(documents: documents, encoder: encoder, primaryKey: primaryKey) { res in
              continuation.resume(returning: res)
          }
      }
}

Proposal is to add these bridging methods for all methods on Indexes in perhaps an Indexes+async.swift extension. Additionally unit tests will need to be added to cover async calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions