Promisekit: Firstly: Cannot convert return expression of type Promise<_.T>

Created on 15 Mar 2018  路  2Comments  路  Source: mxcl/PromiseKit

Hi Matt,

I believe I found an issue with firstly in latest PromiseKit (6.2.1). This code doesn't compile, the error is Cannot convert return expression of type 'Promise<_.T>' to return type 'Promise<Data>'.

    public func foo() -> Promise<Data> {
        return firstly {
            let data = try Data(contentsOf: URL(fileURLWithPath: "path"))
            return .value(data)
        }
    }

I'm not sure where the problem is, but if I add this code to firstly.swift (explicit use of Promise class instead of Thenable protocol), it starts working.

public func firstly<T>(execute body: () throws -> Promise<T>) -> Promise<T> {
    do {
        let rp = Promise<T>(.pending)
        try body().pipe(to: rp.box.seal)
        return rp
    } catch {
        return Promise(error: error)
    }
}

Thanks for all your work!

Most helpful comment

As per our troubleshooting guide, specify the return type:

public func foo() -> Promise<Data> {
    return firstly { () -> Promise<Data> in
        let data = try Data(contentsOf: URL(fileURLWithPath: "path"))
        return .value(data)
    }
}

All 2 comments

As per our troubleshooting guide, specify the return type:

public func foo() -> Promise<Data> {
    return firstly { () -> Promise<Data> in
        let data = try Data(contentsOf: URL(fileURLWithPath: "path"))
        return .value(data)
    }
}

Ah, I feel bad for not figuring this out myself. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Banck picture Banck  路  4Comments

jshier picture jshier  路  4Comments

adrianbg picture adrianbg  路  6Comments

drekka picture drekka  路  5Comments

rlam3 picture rlam3  路  5Comments