Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Async Overloads for All Public Functions #427

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 235 additions & 0 deletions Sources/MeiliSearch/Async/Client+async.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
import Foundation

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension MeiliSearch {
/**
See `createIndex(uid:primaryKey:_:)`
*/
public func createIndex(uid: String, primaryKey: String? = nil) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.createIndex(uid: uid, primaryKey: primaryKey) { result in
continuation.resume(with: result)
}
}
}

/**
See `getIndex(_:_:)`
*/
public func getIndex(_ uid: String) async throws -> Index {
try await withCheckedThrowingContinuation { continuation in
self.getIndex(uid) { result in
continuation.resume(with: result)
}
}
}

/**
See `getIndexes(params:_:)`
*/
public func getIndexes(params: IndexesQuery? = nil) async throws -> IndexesResults {
try await withCheckedThrowingContinuation { continuation in
self.getIndexes(params: params) { result in
continuation.resume(with: result)
}
}
}

/**
See `updateIndex(uid:primaryKey:_:)`
*/
public func updateIndex(uid: String, primaryKey: String) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.updateIndex(uid: uid, primaryKey: primaryKey) { result in
continuation.resume(with: result)
}
}
}

/**
See `deleteIndex(_:_:)`
*/
public func deleteIndex(_ uid: String) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.deleteIndex(uid) { result in
continuation.resume(with: result)
}
}
}

/**
See `waitForTask(taskUid:options:_:)`
*/
public func waitForTask(taskUid: Int, options: WaitOptions? = nil) async throws -> Task {
try await withCheckedThrowingContinuation { continuation in
self.waitForTask(taskUid: taskUid, options: options) { result in
continuation.resume(with: result)
}
}
}

/**
See `waitForTask(task:options:_:)`
*/
public func waitForTask(task: TaskInfo, options: WaitOptions? = nil) async throws -> Task {
try await withCheckedThrowingContinuation { continuation in
self.waitForTask(task: task, options: options) { result in
continuation.resume(with: result)
}
}
}

/**
See `getTask(taskUid:_:)`
*/
public func getTask(taskUid: Int) async throws -> Task {
try await withCheckedThrowingContinuation { continuation in
self.getTask(taskUid: taskUid) { result in
continuation.resume(with: result)
}
}
}

/**
See `getTasks(params:_:)`
*/
public func getTasks(params: TasksQuery? = nil) async throws -> TasksResults {
try await withCheckedThrowingContinuation { continuation in
self.getTasks(params: params) { result in
continuation.resume(with: result)
}
}
}

/**
See `cancelTasks(filter:completion:)`
*/
public func cancelTasks(filter: CancelTasksQuery) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.cancelTasks(filter: filter) { result in
continuation.resume(with: result)
}
}
}

/**
See `deleteTasks(filter:completion:)`
*/
public func deleteTasks(filter: DeleteTasksQuery) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.deleteTasks(filter: filter) { result in
continuation.resume(with: result)
}
}
}

/**
See `getKeys(params:_:)`
*/
public func getKeys(params: KeysQuery? = nil) async throws -> KeysResults {
try await withCheckedThrowingContinuation { continuation in
self.getKeys(params: params) { result in
continuation.resume(with: result)
}
}
}

/**
See `getKey(keyOrUid:_:)`
*/
public func getKey(keyOrUid: String) async throws -> Key {
try await withCheckedThrowingContinuation { continuation in
self.getKey(keyOrUid: keyOrUid) { result in
continuation.resume(with: result)
}
}
}

/**
See `createKey(_:_:)`
*/
public func createKey(_ keyParams: KeyParams) async throws -> Key {
try await withCheckedThrowingContinuation { continuation in
self.createKey(keyParams) { result in
continuation.resume(with: result)
}
}
}

/**
See `updateKey(keyOrUid:keyParams:_:)`
*/
public func updateKey(keyOrUid: String, keyParams: KeyUpdateParams) async throws -> Key {
try await withCheckedThrowingContinuation { continuation in
self.updateKey(keyOrUid: keyOrUid, keyParams: keyParams) { result in
continuation.resume(with: result)
}
}
}

/**
See `deleteKey(keyOrUid:_:)`
*/
public func deleteKey(keyOrUid: String) async throws {
try await withCheckedThrowingContinuation { continuation in
self.deleteKey(keyOrUid: keyOrUid) { result in
continuation.resume(with: result)
}
}
}

/**
See `allStats(_:)`
*/
public func allStats() async throws -> AllStats {
try await withCheckedThrowingContinuation { continuation in
self.allStats { result in
continuation.resume(with: result)
}
}
}

/**
See `health(_:)`
*/
public func health() async throws -> Health {
try await withCheckedThrowingContinuation { continuation in
self.health { result in
continuation.resume(with: result)
}
}
}

/**
See `isHealthy(_:)`
*/
public func isHealthy() async -> Bool {
await withCheckedContinuation { continuation in
self.isHealthy { result in
continuation.resume(returning: result)
}
}
}
Sherlouk marked this conversation as resolved.
Show resolved Hide resolved

/**
See `version(_:)`
*/
public func version() async throws -> Version {
try await withCheckedThrowingContinuation { continuation in
self.version { result in
continuation.resume(with: result)
}
}
}

/**
See `createDump(_:)`
*/
public func createDump() async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.createDump { result in
continuation.resume(with: result)
}
}
}
}
Loading
Loading