Having a purpose on your mind keeps your thoughts from devolving into chaos and bad moods. You can't stop your mind from thinking, but when you have a goal to think about, your mental resources are less likely to drift randomly into upsetting thoughts. They have someplace to go. That's why studies show that people are more often in a good mood while working than they are in their free time. It seems unbelievable at first, but it is easily explained by the need for purpose.
Most people are more likely to have clear purposes at work than at home.
The human mind needs a purpose. It's like the ocelot scratching off his fur at the Seattle Zoo. The zookeepers didn't know what to do about it. They gave him a female, but he kept skinning himself. They changed his diet.