❔ Callback consumer to async Task
Hello
I'm trying to convert a callback based method to an async task.
The basic idea is I have a message bus where I can send messages.
Some of these messages require a response from the other end.
I can easily do this with a callback based system, but I would like to convert it to a
async/await
.
I have created this example (I know the code is invalid, it just serves as a sketch).
Is there a standardised way to do this? I have not been able to find it on stackoverflow.
4 Replies
When you ask: "is there a standardized way to do this?" I'm not really sure what "this" refers to.
Looking at your code my first reaction is that it's not thread safe.
you're looking for
TaskCompletionSource
@ArkobatYeah, this seems to be exactly what I’m looking for.
Thanks🙏🏼
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.