How can I remove the Bool return from my function without getting the error:
Generic parameter 'T' could not be inferred
This is the function:
private func syncDataStore() async throws -> Bool {
try await withUnsafeThrowingContinuation { continuation in
Amplify.DataStore.stop { (result) in
switch(result) {
case .success:
Amplify.DataStore.start { (result) in
switch(result) {
case .success:
print("DataStore started")
continuation.resume(returning: true)
case .failure(let error):
print("Error starting DataStore:\(error)")
continuation.resume(throwing: error)
}
}
case .failure(let error):
print("Error stopping DataStore:\(error)")
continuation.resume(throwing: error)
}
}
}
}
This is what I tried to do but I get the error mentioned above:
private func syncDataStore() async throws {
try await withUnsafeThrowingContinuation { continuation in
Amplify.DataStore.stop { (result) in
switch(result) {
case .success:
Amplify.DataStore.start { (result) in
switch(result) {
case .success:
print("DataStore started")
continuation.resume()
case .failure(let error):
print("Error starting DataStore:\(error)")
continuation.resume(throwing: error)
}
}
case .failure(let error):
print("Error stopping DataStore:\(error)")
continuation.resume(throwing: error)
}
}
}
}
Honestly I don't know why it's complaining, no returns are there and it's not tie to any model or anything...
The trick is to cast return value of withUnsafeThrowingContinuation to Void, like so:
try await withUnsafeThrowingContinuation { continuation in
someAsyncFunction() { error in
if let error = error { continuation.resume(throwing: error) }
else { continuation.resume() }
}
} as Void
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With