Except, that doesn't happen like you described it. A process can "prevent sleep", at which point closing the lid will still leave the laptop running (you can view apps/processes that do this in Activity Monitor - there is a separate column titled "Preventing sleep").