apivideo / api.video-csharp-client

The official C# client library for api.video
https://api.video
MIT License
25 stars 1 forks source link

[Feat]: Make methods async #132

Closed ChoOo7 closed 1 month ago

ChoOo7 commented 1 month ago

Version

1.4.0

Environment that reproduces the issue

You are using openapi-geneartor to generate this project https://github.com/OpenAPITools/openapi-generator

For the c# version, there is a parameter named operationIsAsync & operationResultTask https://openapi-generator.tech/docs/generators/aspnetcore/

It's a good practise to use async Task for scalability prupose https://medium.com/@frederikbanke/improving-scalability-in-c-using-async-and-await-f97af1466922

But maybe it's not possible by the tool you are using ? https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpFunctionsServerCodegen.java#L611 It's looking like async is forced to false if target is a lib :/ don't know why....

Please, can you try this approche and generate a new nuget package ?

Thanks

Use case description

Look at reproduce

Proposed solution

Look at reproduce

Alternative solutions

Look at reproduce

olivierapivideo commented 1 month ago

Hi @ChoOo7 ,

Thanks for your feedback. We'll try to implement this as soon as possible (probably next week).

Regards

olivierapivideo commented 1 month ago

Hi @ChoOo7 ,

We've just released v1.5.0 with the addition of *Async() methods.

You can now write things like that:

var cancellationToken = new System.Threading.CancellationToken(); // cancellationToken is optionnal
var task = apiVideoClient.Videos().createAsync(new VideoCreationPayload { title = "My video" }, cancellationToken).ContinueWith(task =>
{
    if (task.IsFaulted)
    {
        Console.WriteLine("An error occured: " + task.Exception.Message);
    }
    else
    {
        var video = task.Result;
        Console.WriteLine("Video successfully created: " + video);
    }
});

or:

var video = await apiVideoClient.Videos().createAsync(new VideoCreationPayload { title = "My video" });

Please let us know if this meets your needs. If so, I will close this issue.

Regards

SimonMinottoSociabble commented 1 month ago

Thanks, i'll test it and give you a feedback

ChoOo7 commented 1 month ago

I see async methods, but some are not valid, the live delete one for example should return a Task, not void image

If you generate a new nuget package, can you implement the new live complete method please ?

"Pour ce faire vous devez appeler PUT /live-streams/{liveStreamId}/complete sans body. Cela répondra un 202 et le live s'arrêtera peu de temps après"

olivierapivideo commented 1 month ago

Hi @ChoOo7 , We'll release a new version early next week, which will include the livestreams.complete method, as well as a fix for the bug you point out here.

olivierapivideo commented 1 month ago

Hi @ChoOo7

We've released v1.6.0 with the following changes:

Regards

olivierapivideo commented 1 month ago

Closing this one, feel free to reopen if needed :)