Answer the question
In order to leave comments, you need to log in
How to organize two-way asynchronous communication between the components of one application?
Practice app for synchronizing the contents of two folders.
There is a class that can synchronize two folders passed to it (let's call it a synchronizer), there is a separate console application that can interact with the user and transfer data to the synchronizer (attempts at a clean architecture).
Periodically, when an exception occurs at the synchronizer, it passes this information to the console application using event, and it writes to the log (you can also display it on the screen). Such a one-way transfer of information, if I understand correctly, in addition to events, can also be implemented on Rx, and on async streams that appeared in C# 8.
Now there is a task - when an exception occurs, ask the user whether to continue the process or abort. This requires two-way asynchronous communication: the synchronizer sends a request to the top and waits for a response. It seems that gRPC would be suitable for larger scales, but what to use inside a small program? I would like to master some pattern in the future, applicable in "normal", large applications.
Answer the question
In order to leave comments, you need to log in
Gathered in a bunch of async streams, events, rx, and even gRPC.
You can try System.Threading.Channels, you just need to create a channel for each direction.
With them, just interaction occurs through async streams.
Further I will call the synchronizer "agent", and the user "controller".
If an exception occurs, then the "agent" sends an appropriate message to the "controller" and waits for a command from him what to do next.
If the "controller" sends a command to shut down, both channels are closed and the "agent" is turned off.
If the "controller" sends a command to continue working, then the "agent" returns to work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question