The Talmud explores the issue of how someone mourns on the Sabbath after burying his relative. There was a debate between the sages in Babylon and Rabbi Yohanon in Israel over what this person should do. The authorities in Babylon forbid noticeable mourning practices on the Sabbath and even allowed a mourner to engage in marital intimacy that day. However, later sages in Babylon followed Rabbi Yohanon and ruled that while public signs of mourning were not acceptable on the Sabbath, private expressions of grief were still required.
The Gemara brings a story of a man who went ahead and slept with his wife on the first Sabbath of his mourning. His fate was that when he passed away, pigs devoured his body, or some say only his penis. Either way, he was dishonored for his lustful act when he should have been privately mourning his relative.
What was this man thinking? Jewish law actually teaches that sexual intimacy is a key component of marriage. See Mishpatim for an explanation of how this is derived from scripture itself. There is a Mishnah (Talmud, Ketuvot 61b) that if a man vows not to have (intimate) pleasure from his wife for over a week, she is entitled to divorce him and get paid the value of her marriage contract. The reverse also applies: a woman who withholds herself from her husband loses her marriage contract.
The Mishnah details that the wives of men who are away from home for long periods such as camel drivers and sailors cannot expect such a frequency. If a man wants to change his profession to one that will require him to be away from home, his wife can veto this on account of the reduction in marital intimacy.
So it appears that the man in question had a rational basis for his choice. However, the Mishnah and Gemara rule here that we must observe private practices of mourning, including refraining from intimacy. In a normal relationship people can control themselves for a week while they work through the grief of losing a family member. It appears that by choosing instead to pig out during that time, this man was punished by pigs.
It is important to be able to balance our priorities in life. We have important goals but sometimes they must be temporarily shelved to focus on a specific event or situation. This is not to say that one item is more important than the other. However, a wise man learns to delay gratification to focus on what needs to be accomplished immediately.