Async Sleep Problem
This lesson discusses how we can implement a method similar to asyncio.sleep API.
We'll cover the following...
Async Sleep Problem
Problem
Asyncio already provides us with an API to sleep asynchronously asyncio.sleep()
. In fact, this is one of the most commonly used asyn APIs in introductory examples explaining async.io. The problem at hand is to implement our own coroutine that sleeps asynchronously. The signature of the coroutine is as follows.
# Implement the following coroutine where
# sleep_for is defined in seconds
async def asleep(sleep_for):
pass
This makes for an excellent interview problem as it is small enough to be completed in an hour and tricky enough to test a candidate's thought-process. ...