-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
427: Generate Async Overloads for All Public Functions r=Sherlouk a=Sherlouk # Pull Request ## Related issue Fixes #332 This is NOT a breaking change. ## What does this PR do? - Adds async/await overloads to all public interfaces. The contents of these files has been automatically generated using [Sourcery](https://github.com/krzysztofzablocki/Sourcery) using [this template](https://gist.github.com/Sherlouk/fa3e49e24f9be7232c642b945177b05e) I made. It does not include documentation, I feel like this is an okay compromise at this point in time and is something that can be incremented on in the future, potentially when we move over entirely. Async/Await functions sit in Xcode along with the normal closure based methods and so is easy to see the documentation inline anyway. The template has been shared to hopefully make it easier to update when new APIs are added in the future, keeping maintenance down. With the previous PR (#410) I called the underlying implementation directly, this leads to unnecessary duplication with other functions. Instead I call the non-async function guaranteeing consistent functionality, and no unnecessary duplication. I also feel like this avoids the need for excessive and additional test coverage, so long as the build compiles then the implementation is working as expected and tests give us no extra confidence that it's working as expected. We'll keep the one for search to demonstrate. `@aronbudinszky` Are you happy with this approach too? ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: James Sherlock <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,127 additions
and
1,113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
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) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.