jensenkd / plex-api

.NET Core SDK for Plex Media Server
MIT License
86 stars 27 forks source link

Avoid blocking calls in models constructors #72

Closed Ombrelin closed 2 years ago

Ombrelin commented 2 years ago

Is your feature request related to a problem? Please describe. I'm developing a client app (using .NET MAUI) using the library, and the blocking calls in the constructor are a pain.

Describe the solution you'd like I would recommend fecthing the data before constructing the models and then passing the data to map to the constructor

Describe alternatives you've considered For now I wrap the calls with Task.Run(...) but the overhead and blocking makes the calls very slow.

Ombrelin commented 2 years ago

Would you accept a PR if I wrote overloads of the existing methods but in a non-blocking fashion ?

fxsth commented 2 years ago

What about using the clients' async methods instead of the models' constructors? They are async and non-blocking, seems to be the solution to your problems. E.g. PlexAccountClient.GetPlexAccountAsync(username, password) instead of PlexAccount(..., username, password)

Still I don't have a clue why there are specific models that have an api call in its constructor. Unless I have missed something, I consider this an anti pattern.

Ombrelin commented 2 years ago

Thank you for your suggestion ! I did not notice that these methods were on the clients. I works well in my use case. Thank you for provide this workaround.