I have the following client-server style pseudo-code:
public void GetGrades() {
var msg = new Message(...); // request in here
QueueRequest?.Invoke(this, msg); // add to outgoing queue
}
In another processor class I have a loop :
// check for messages back from server
// server response could be a "wait", if so, wait for real response
// raise MessageReceived event here
// each message is then processed by classes which catch the event
// send new messages to server
if (queue.Any()){
var msg = queue.Dequeue();
// send to server over HTTP
}
I have heavily simplified this code so its easy to see the purpose of my question.
Currently I call this code like so:
student.GetGrades(); // fire and forget, almost
But I have a less than ideal way of knowing when the result comes back, I basically use events:
I raise MessageReceived?.Invoke(this, msg);
then catch this at another level StudentManager
which sets the result on the specific student object.
But instead I would like to wrap this in async await
and have something like so:
var grades = await GetGrades();
Is this possible in such disconnected scenarios? How would I go about doing it?