I am familiar with how to write common delegates and subscribing to them, but is there a way to have the usefulness of delegates (subscribing and unsubscribing from other classes) with the awaitable functionality?
For example, with a simple delegate like this:
public delegate void SimpleDelegate();
public static SimpleDelegate OnDelegateInvoke;
I then can subscribe to it from another class like:
public void SomeFunction(){};
OnDelegateInvoke += SomeFunction();
The behaviour I want is for the OnDelegateInvoke call to be awaitable, so it awaits there until all subscribed functions complete:
await OnDelegateInvoke?.Invoke();
await DoSomethingThatNeedsAboveCompleted();
I tried writing the delegates with a Task return type but to my understanding that wouldn't work since there are multiple functions returning multiple tasks, so the await would only wait for the first Task to complete.
Since thinking about this I am also not sure if this completely breaks the paradigm of why delegates are useful, so answers about that are also appreciated.