I am using akka.NET. In most cases we use akka like this:
class ActorA : UntypedActor
{
public delegate void EventHandler(object arg1, object arg2, ...);
public static event EventHandler Event;
}
actorA.Event += some_function;
In this case we execute some_function(arg1, arg2)
whenever Event.Invoke(arg1, arg2)
is called. Now assume that we have an asynchrounous HTTP server, and I am trying to let the server asynchronously await actorA.Event
to happen, after a client calls the server. I do not need to run some_function
when Event
happens, but I have to ensure that the runtime context is switched back into the functions of the HTTP server. That is:
// in the methods of the HTTP server...
public async void AwaitAnEvent()
{
await ReturnOnEvent(actorA.Event);
}
Is it possible to efficiently implement ReturnOnEvent
which returns immediately when the next actorA.Event.Invoke(arg1, arg2)
is called?