Implementation of a sleep function.