signal-csharp / Signal-Windows

Unofficial Signal Private Messenger for Windows
GNU General Public License v3.0
108 stars 31 forks source link

Why is this in a Task.Run? #68

Open golf1052 opened 7 years ago

golf1052 commented 7 years ago

https://github.com/signal-csharp/Signal-Windows/blob/9dfbce3639920e529bf4ac61a5f2ce533cbae342/Signal-Windows/ViewModels/RegisterFinalizationPageViewModel.cs#L111

So I was wondering why this is in a Task.Run. Then I did some digging and I'm now guessing that this is async because InitRegistration has calls inside it that are async but are blocking, to avoid deadlocks with the UI thread this is put into a Task.Run so that it runs on a separate thread.

But why not just have InitRegistration be properly async instead of blocking on network calls?

Trolldemorted commented 7 years ago

You are right, InitRegistration is sending a HTTP request containing the username (aka the phone number).

I have made the top-level functions (like send and receive) of libsignal-service non-async because the callstack through the signal libraries can be rather big, and i didn't want the performance impact for each of these calls, especially since most of these functions return rather quickly.

InitRegistration should be cancelable though, but i didn't have time for that so far.