Asynchronous to Synchronous Problem
Explore how to convert asynchronous execution to synchronous using C# concurrency tools. Understand how to design a solution with monitors and callback wrappers to make the main thread wait for asynchronous tasks to complete, ensuring safe and predictable execution without modifying original code.
Asynchronous to Synchronous Problem
This is an actual interview question asked at Netflix.
Imagine we have an Executor class that performs some useful task asynchronously via the method asynchronousExecution(). Additionally, the method accepts a callback object which implements the Callback interface. The passed-in callback object’s done() method gets invoked when the asynchronous execution is complete. The definition for the involved classes is below:
Callback Interface and Implementation
An example run would be as follows:
Note, the main thread exits before the asynchronous execution is completed. The print-statement from the main thread ...