I'm calling a third-party API which has a method that looks like this:
myServiceClient.Discover(key, OnCompletionCallback);
public bool OnCompletionCallback(string response)
{
// my code
}
My challenge is, I have to call Discover
because it does some work under-the-covers that I need. At the same time, I have to wait for Discover
to complete before running my custom code. To further complicate matters, I can't just put my code in the OnCompletionCallback
handler because I need to call the code above from a Func
delegate. In short, I want to do this:
Func<SystemTask> myFunction = async () =>
{
await myServiceClient.Discover(key);
// my code
}
However, I can't do this because the third-party API uses a callback approach instead of an async/await approach.
Is there some way to make the callback approach work in an async / await world?