Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Void withCheckedThrowingContinuation Generic parameter 'T' could not be inferred

Tags:

swift

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)
                }
            }
        }
    }
like image 897
Rick Avatar asked Sep 12 '25 15:09

Rick


1 Answers

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.

like image 195
Rick Avatar answered Sep 15 '25 11:09

Rick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!