swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[C#] Generate async methods with CancellationToken support

Open jonsa opened this issue 8 years ago • 6 comments

More of a feature request than an issue. Would it be possible to generate async methods with CancellationToken support?

jonsa avatar Sep 26 '17 09:09 jonsa

@jonsa do you mean a method to submit a HTTP request to cancel/void a token somehow?

wing328 avatar Sep 29 '17 10:09 wing328

No I don't, I think? :)

Async methods are usually implemented in two flavors

public Task MyAsync(object arg1, object arg2)
{
    return MyAsync(arg1, arg2, CancellationToken.None);
}

public Task MyAsync(object arg1, object arg2, CancellationToken cancellationToken)
{
    // ...
}

And so does RestSharp RestClient.

What I'd like is for the generated client to use the async methods with CancellationToken support.

I haven't found the time to fully understand what it would take to implement but I've looked around a little to get a sense of it. The way I picture it, it is quite a simple refactoring process.

  1. Any current async method should take an additional CancellationToken argument and be used when using the RestSharp client.
  2. Recreate the previous async method which calls the newly created one by passing all arguments and CancellationToken.None

jonsa avatar Oct 02 '17 06:10 jonsa

@ozziepeeps @wing328 - it looks like the above PR was never merged, and we still don't have CancellationToken support in Swagger. What is the current status?

smflorentino avatar Feb 29 '20 20:02 smflorentino

Hi @smflorentino, you are welcome to merge the PR if it meets your needs. Thanks

ozziepeeps avatar Mar 01 '20 22:03 ozziepeeps

Is there any reason, why the PR is not yet merged, but closed?

zivillian avatar Nov 18 '20 15:11 zivillian

Any update on when this will be available? It's cumbersome ot add the CancellationTokens manually.

BMa-BS avatar Oct 10 '23 09:10 BMa-BS