It is often the case that we hope for something and expect to receive it in a certain way. When we do not receive it as expected, or within the expected time frame, we become susceptible to pessimism and hopelessness. The story of Prophet Yusuf (as) is a wise and compassionate reminder from God Almighty of the superiority of His timing and planning.
When Prophet Yusuf informs his father of his magnificent dream, Prophet Ya’qub (as) responds with the following:
وَكَذَٰلِكَ يَجْتَبِيكَ رَبُّكَ وَيُعَلِّمُكَ مِن تَأْوِيلِ الْأَحَادِيثِ وَيُتِمُّ نِعْمَتَهُ عَلَيْكَ وَعَلَىٰ آلِ يَعْقُوبَ كَمَا أَتَمَّهَا عَلَىٰ أَبَوَيْكَ مِن قَبْلُ إِبْرَاهِيمَ وَإِسْحَاقَ ۚ إِنَّ رَبَّكَ عَلِيمٌ حَكِيمٌ
And thus will your Lord choose you and teach you the interpretation of narratives and complete His favor upon you and upon the family of Jacob, as He completed it upon your fathers before, Abraham and Isaac. Indeed, your Lord is Knowing and Wise. 
One can hardly imagine Prophet Yusuf’s spiritual excitement after being informed by his father that he had been chosen by Almighty Allah. The natural expectation might even be that what is to come next will be a truly prosperous chapter in the life of Prophet Yusuf. However, the verse ends by reminding us that God is All-Knowing and All-Wise, as if foreshadowing that things will not go as expected.
The story continues as we are familiar with. Prophet Yusuf’s brothers lie to their father and essentially kidnap him, abandoning him at the bottom of the well. After being retrieved from the well and sold into slavery, God Almighty again subtly reminds us that He knows best when He says the following:
وَقَالَ الَّذِي اشْتَرَاهُ مِن مِّصْرَ لِامْرَأَتِهِ أَكْرِمِي مَثْوَاهُ عَسَىٰ أَن يَنفَعَنَا أَوْ نَتَّخِذَهُ وَلَدًا ۚ وَكَذَٰلِكَ مَكَّنَّا لِيُوسُفَ فِي الْأَرْضِ وَلِنُعَلِّمَهُ مِن تَأْوِيلِ الْأَحَادِيثِ ۚ وَاللَّهُ غَالِبٌ عَلَىٰ أَمْرِهِ وَلَٰكِنَّ أَكْثَرَ النَّاسِ لَا يَعْلَمُونَ
And the one from Egypt who bought him said to his wife, “Make his residence comfortable. Perhaps he will benefit us, or we will adopt him as a son.” And thus, We established Joseph in the land that We might teach him the interpretation of events. And Allah is predominant over His affair, but most of the people do not know. 
God explains that those events were part of His plan to teach Prophet Yusuf the interpretation of dreams, as Prophet Ya’qub had prophesied. And yet again, the verse concludes on a rather mysterious, mystic note. God tells His audience, the readers of His glorious book, that He is the master of His affairs, although most people don’t know.
That is to say, when God intends to do something, He will. Unfortunately, many people do not realize this, imposing their expectations on God, thereby limiting Him in their understandings. We expect things to happen in a certain way, and when they do not, we immediately conclude that God does not plan – or is unable (God forbid) – to make them happen.
The story continues. Prophet Yusuf ends up unjustly imprisoned for several years. Eventually, he is released and elevated by God in the socio-political sphere, essentially becoming the treasurer of all of Egypt. Through the famine and Prophet Yusuf’s position in the kingdom, his family is, at last, reunited. When Prophet Ya’qub finally arrives in Egypt with his wife and sons, they all perform the foreshadowed prostration in the presence of Prophet Yusuf. Upon seeing this scene, he exclaims to God Almighty:
رَبِّ قَدْ آتَيْتَنِي مِنَ الْمُلْكِ وَعَلَّمْتَنِي مِن تَأْوِيلِ الْأَحَادِيثِ ۚ فَاطِرَ السَّمَاوَاتِ وَالْأَرْضِ أَنتَ وَلِيِّي فِي الدُّنْيَا وَالْآخِرَةِ ۖ تَوَفَّنِي مُسْلِمًا وَأَلْحِقْنِي بِالصَّالِحِينَ
My Lord, You have given me [something] of sovereignty and taught me of the interpretation of dreams. Creator of the heavens and earth, You are my protector in this world and in the Hereafter. Cause me to die a Muslim and join me with the righteous. 
At this point, the interpretation of the dream that initiated the great journey of Prophet Yusuf’s life becomes clear. God finally carried out what He originally intended – completing Prophet Yusuf’s ability to interpret dreams. After the betrayal of his brothers, the solitude of the well, the years spent in slavery and imprisonment in a foreign land, Prophet Yusuf was ultimately led to this high and noble position.
Let us now return our focus to the initial concepts of divine timing and planning. God Almighty knew all along exactly how the scroll of Prophet Yusuf’s life was to unfold. Even through the betrayal, the abandonment, the solitude, the slavery, and the imprisonment, God was always in full control of Prophet Yusuf’s well-being. The impatient and faithless would become complacent and even rebellious towards God throughout such an ordeal. Yet, Prophet Yusuf understood that even though the circumstances were exhausting, and even though the journey might have seemed endless, God was with him.
Each and every one of us is the Prophet Yusuf (as) of our own story. Let us purify our hearts and minds so that we are able to faithfully trust that God is always present and active in our affairs. No matter how difficult or long a trial might seem, God is certainly planning something better for us behind the scenes. Perhaps after our difficulties, stresses, struggles, tears, and prayers, God will elevate us as He did His noble prophet. Perhaps, in our own respects, God will take us from slavery and imprisonment to freedom and prosperity. Let us find hope and comfort in God’s timing and planning rather than our own. We are all Yusuf. Quran: Chapter 12, Verse 6
 Quran: Chapter 12, Verse 21
 Quran: Chapter 12, Verse 101