Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of CancellationToken #212

Open
1 of 2 tasks
petrkoutnycz opened this issue Dec 12, 2022 · 2 comments
Open
1 of 2 tasks

Support of CancellationToken #212

petrkoutnycz opened this issue Dec 12, 2022 · 2 comments

Comments

@petrkoutnycz
Copy link

petrkoutnycz commented Dec 12, 2022

Description

Cancellation support in OpenApiClientProvider.

Repro steps

Please provide the steps required to reproduce the problem

  1. Use a provider according this page: https://fsprojects.github.io/SwaggerProvider/#/OpenApiClientProvider

  2. Generated client contains methods without a support for cancellation tokens

Expected behavior

Generated methods accept CancellationToken instance.

Actual behavior

It is not possible to provide my own instance of CancellationToken.

Affected Type Providers

  • SwaggerClientProvider
  • OpenApiClientProvider

Related information

  • Operating system - macOS Ventura
  • .NET Runtime, CoreCLR or Mono Version - .NET 6 SDK
@sergey-tihon
Copy link
Member

It definitely make sense, when we generate methods that return Task<_>, but it will require emitting different code for Tasks with manual cancelation checks - https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/task-expressions#adding-cancellation-tokens-and-cancellation-checks

As workaround we can use async that automatically instrumented by cancellation token

[<Literal>]
let Schema = "https://petstore.swagger.io/v2/swagger.json"
type PetStore = OpenApiClientProvider<Schema, PreferAsync=true>


let store = PetStore.Client()
let task = Async.StartAsTask(store.GetPetById(42L), cancellationToken)

@petrkoutnycz
Copy link
Author

Nice workaround, did not realize it. Yeah, you're right. I am mostly speaking about Task<_> and since it is natively supported in F# now, it would be nice to be able to cancel it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants