Comments (9)
Hi @RahavLussato. BrightFutures uses typed errors and therefore doesn't directly work with Swift's untyped throws
. The alternative is to use the flatMap
variant that allows you to return a Result: https://github.com/Thomvis/BrightFutures/blob/master/Sources/BrightFutures/AsyncType+ResultType.swift#L72.
from brightfutures.
Thanks @Thomvis , can you help me how should i write this ?
i tried like this but its not compiling, "Cannot invoke 'flatMap' with an argument list of type '(@escaping (JSON) -> Result)'"
return client.call(method: method, params: json).flatMap { (json:JSON) -> Result<JSON> in
var result: Result<JSON, Error>
do {
let response = try self.decoder.decode(responseType, from: json.rawData())
DDLogDebug("call process \(json)")
result = response
}
catch let error {
DDLogError("Parse \(method) response failed: \(json) with error \(error.localizedDescription)")
result = error
}
return result
}
from brightfutures.
A couple of things:
- the result type of your closure is defined as
Result<JSON>
but should beResult<JSON, Error>
- when you assign
response
toresult
, you need to use the correct result enum case, soresult = .success(response)
- same goes for the error case (wrap it in
.failure
)
from brightfutures.
Thanks @Thomvis but still getting errors :(
- Cannot invoke 'flatMap' with an argument list of type '(@escaping (JSON) -> <>)'
- Generic type 'Result' specialized with too many type parameters (got 2, but expected 1)
return client.call(method: method, params: json).flatMap { (json:JSON) -> Result<JSON, Error> in
var result: Result<JSON, Error>
do {
let response = try self.decoder.decode(responseType, from: json.rawData())
DDLogDebug("call process \(json)")
result = .success(response)
}
catch let error {
DDLogError("Parse \(method) response failed: \(json) with error \(error.localizedDescription)")
result = .failure(response)
}
return result
}
from brightfutures.
from brightfutures.
It seems like the compiler is confused about which Result type to use. Do you or any of your dependencies declare one with a single type parameter?
from brightfutures.
nothing that I can find, can I specify it?
from brightfutures.
now it compiled :)
return client.call(method: method, params: json).flatMap { (json:JSON) -> Swift.Result<T, Error> in
var result: Swift.Result<T, Error>
do {
let response = try self.decoder.decode(responseType, from: json.rawData())
DDLogDebug("call process \(json)")
result = .success(response)
}
catch let error {
DDLogError("Parse \(method) response failed: \(json) with error \(error.localizedDescription)")
result = .failure(error)
}
return result
}
from brightfutures.
@Thomvis so does it going to return to the right callback (onSuccess / onFailure) by the type of the result ?
from brightfutures.
Related Issues (20)
- Swift4: build failure HOT 1
- Failed when compiling Bitcode HOT 1
- Promise chaining in BrightFutures using flatMap HOT 3
- Compile error on Xcode 9.3 beta 3 HOT 2
- Swift 4.1 support release HOT 2
- Swift 4.1 Crashes HOT 3
- Generic parameter 'T' could not be inferred HOT 1
- Compile error with XCode 9.3 / Swift 3.3 HOT 1
- Developers in danger!
- Update to Result 4.0.0 (or not) HOT 2
- Conflict with seconds and milliseconds shortcuts HOT 7
- Carthage issue with Result version choosing HOT 2
- Crash app when execute many times Future objects HOT 5
- Synchronous resolution of Futures HOT 2
- High crash rate after upgrade to Xcode 10 HOT 3
- Update to Result -> 4
- Support Swift 5 HOT 2
- Apparent dealloc error after Swift 5/Xcode 10.3 upgrade HOT 10
- 8.0.1 not available on Cocoapods
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brightfutures.