Say you have 10 functions in C# that call each other. They all work fine. Later on the lowest function changes so it needs to call an api and await
something. That means the function must be async
. Now each
function that calls that function must also await
& be async
.
Is there a way to break that?
As it is, I have to change all the functions that are related to that async
functions into async
functions. It's a hassle and I was wondering if there's something like the FutureBuilder for C#?
FutureBuilder
is a way to build a UI that reacts to futures as they complete.
There's nothing built-in to .NET that does a similar thing, but it's not too hard to build your own or use something from a library. Library solutions include MvxNotifyTask
from MvvmCross, ObservableObject.TaskNotifier
from the .NET Community Toolkit / MVVM Toolkit v7 (previously known as NotifyTaskCompletion<T>
in v6), or NotifyTask<T>
in Nito.Mvvm.Async.
Most implementations are more or less derived from this old article of mine, but note that the sample code for that article has a bug when creating a NotifyTaskCompletion<T>
from an already-completed task, so don't use it; use one of the implementations above or write your own instead.