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!
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!
Most helpful comment
As per our troubleshooting guide, specify the return type: