Open marc-mueller opened 7 years ago
Hoi Marc :)
Async/await is already supported by the generated clients, just call:
let result = await client.getXY().toPromise();
Maybe we should add an option "UsePromises" to call this method internally... or generate a second method "getXYAsync()" which returns a promise?
(it would be cool if Observable would just inherit from Promise...)
Hi Rico
Thanks for the quit response. Yes, we could already use it with the current version by applying the toPromise()
function to the call. My understanding of a client code generator is that it generates the code we need and implements all the "boilerplate code" we would repetitively add to the usage of the client. Therefore the option "UsePromises" would be great to be directly implemented into the generator.
I'm currently not sure if generating both versions in the same class or just generate one or the other would be the better solution. Normally you define one pattern on how to interact / write code and therefore a switch for one or the other version would better leverage that situation.
Calling toPromise() will make it impossible to cancel the request, since promises doesn't support cancellation.
@nerfpops you are right, but we can still provide an option for that...
Hi @RicoSuter Is this option available yet? Thanks
any update on this issue? since topromise method is deprecated as of angular12 and will be removed soon..
We are currently defining our implementation stack and we'd like to use NSwag to generate multiple client packages for our Angular application.
One thing with is being discussed right now is if we should use async / await for the Angular implementation. If so, it would be handy if there was a TypeScript template providing the client implementation with async methods. Is this on the roadmap?
The idea is basically to convert the Observable to a Promise to be able to declare the method as async: