...

/

Asynchronous to Synchronous Problem

Asynchronous to Synchronous Problem

In this lesson, we will study a​ real-life interview question asking to convert asynchronous execution to synchronous execution.

We'll cover the following...

Asynchronous to Synchronous Problem

This is an actual interview question asked at Netflix.

Imagine we have an AsyncExecutor class that performs some useful task asynchronously via the method execute(). In addition, the method accepts a function object that acts as a callback and gets invoked after the asynchronous execution is done. The definition of the involved classes is below. The asynchronous work is simulated using sleep. A passed-in call is invoked to let the invoker take any desired action after the asynchronous processing is complete.

Executor Class

class AsyncExecutor

  def work(callback)
    sleep(5)
   
...