You're thinking of Deferred Gratification, and specifically the results of the Stanford Marshmallow Experiment. Basically they put a marshmallow in front of children and said, "You can eat this marshmallow now, but if you
don't eat it then when I get back you will get a
second marshmallow". Then they leave the room and come back something like 10 minutes later.
https://en.wikipedia.org/wiki/Deferred_gratification
https://en.wikipedia.org/wiki/Stanford_marshmallow_experimen...
It's not mentioned in those articles, but one of the differences in those who didn't eat the marshmallow was that they used coping strategies to distract themselves. Things like singing to themselves, looking around the room, or drumming on the table. I think I recall a follow-up experiment that's not mentioned in those articles where they taught these coping strategies to a group of children then ran the experiment and, sure enough, far more of them were able to resist eating the marshmallow than in the control group.