For example, we have some action and method, on which the event is being subscribed:
// some response property
static _response {get; set;}
// client sends the post request
[HttpPost]
public async Task<ActionResult> SomeAction(Model someModel)
{
if (someModel != null)
{
// here we subscribing on event
SomeEventHandler.Subscribe(MethodBeingFired)
// here we must wait for firing the event and check if event has been fired
if (eventBeenFired) return Json(new { response = _response })
// or if some wait time's out
return Json(new { error = "Time for executing your request is out" });
}
}
public void MethodBeingFired(SomeEventResult result)
{
// here we have to notify the action in a current thread that event has been fired
eventBeenFired = true;
_response = result.Response;
}
I guess that the code scheme above is pretty clear and understandable. My action should wait some time for capturing the event and return the response or error.