Ibn rajab and others gave an account of a worshipper who ran out of resources while he was in makkah.He became extremely hungry and was about to die from lack of nourishment.One day,as he was wandering in the streets of Makkah,he found an expensive golden neclace.He put it in to his pocket and headed for the mosque.On his was he came across a man who was announcing that he had lost a necklace.The poor man later said,"I ask to describe it to me, and he did so perfectly,leaving no room for doubt.I gave him the necklace without taking any reward from him.I said:O' Allah,I have given it up for you,so compensate me with what is better."He then went to the ocean and began a journey in a small boat.Only a brief period of time passed before a storm came with heavy winds crashing in tot he boat.The boat smashed in to pieces and the man was forced to cling to a piece of wood.The violent winds propelled him to the left and to the right.Finally,he was washed ashore onto an island.He found there a mosque filled with people who were praying,so he joined them.He found papers with parts of the Qur'an written on them and he began to recite from them.The people of the island asked him, "do you read the Qur'an?" he answered in the affirmaive.They said, "Teach our children the Qur'an."So he began to teach them,and he took a salary for his services.One day,they found him writing and they asked,"Will you teach our children to write?"Again he answered in the affirmative and began teaching them for a salary.
A short time later they said to him,"There is an orphaned girl with us whose father was a good man.Will you marry her?"He agreed to the marriage and later related,"I married her and when I saw her on the wedding night,she was no less beautiful than the maiden of paradise and I found that she was wearing that exact same necklace.I asked her to tell me the story of the necklace.She said that her father lost it in makkah and a man found it and returned it to him.She said that her father would always supplicate while prostrating for her daughter to become blessed with a husband similar to that honest man.I then informed her that I was that man."
He abandoned something for the sake of Allah,so Allah compensated him with something that was better.Thus he followed piety and patience and Allah(swt) made success and happiness follow him.
Source:Taken from the book Dont' be sad.