I'm unable to get withCheckedThrowingContinuation
to compile when there’s no return type. For example:
public
func
write(toDevice inDeviceID: Int, atAddress inAddr: Int, value inVal: Float)
async
throws
{
try await withCheckedThrowingContinuation
// ^ Generic parameter 'T' could not be inferred
{ inCont in
self.workQ.async
{
do
{
self.deviceID = inDeviceID
try self.write(address: inAddr, value: inVal)
inCont.resume()
}
catch (let e)
{
inCont.resume(throwing: e)
}
}
}
}
A version that returns works just fine:
public
func
readRegister(address inAddr: Int, fromDevice inDeviceID: Int)
async
throws
-> UInt16
{
try await withCheckedThrowingContinuation
{ inCont in
self.workQ.async
{
do
{
self.deviceID = inDeviceID
let r = try self.readRegister(address: inAddr)
inCont.resume(returning: r)
}
catch (let e)
{
inCont.resume(throwing: e)
}
}
}
}
As I was writing this I found being explicit like this works:
public
func
write(toDevice inDeviceID: Int, atAddress inAddr: Int, value inVal: Float)
async
throws
{
try await withCheckedThrowingContinuation
{ (inCont: CheckedContinuation<Void, Error>) -> Void in
self.workQ.async
{
do
{
self.deviceID = inDeviceID
try self.write(address: inAddr, value: inVal)
inCont.resume()
}
catch (let e)
{
inCont.resume(throwing: e)
}
}
}
}
I filed a bug with Apple.
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