(Exodus 17:16:) "FROM GENERATION TO GENERATION." David said: The Holy One, blessed be He, said, "From generation to generation," and I am after them for generations of generations. Rabbi Eliezer, Rabbi Joshua, and Rabbi Jose differed. Rabbi Eliezer says: From the generation of Moses until the generation of Samuel. Rabbi Joshua says: From the generation of Samuel until the generation of Mordecai and Esther. And Rabbi Jose said: From the generation of Mordecai and Esther until the generation of the King Messiah, which is three generations. And how do we know that the generation of the King Messiah is three generations? As it is said (Psalms 72:5): "They shall fear You with the sun, and before the moon, generation of generations." "A generation" is one; "generations" is two; here are three. Rabbi Berekhyah said in the name of Rabbi Abba bar Kahana: As long as the seed of Amalek exists in the world, it is, as it were, as though a wing covers the Face. Once the seed of Amalek has perished from the world, the wing is removed, as it is said (Isaiah 30:20): "And your Teacher shall no longer hide Himself."
Midrash Tanchuma Buber, Ki Teitzei 18:2
Midrash Tanchuma Buber, Ki Teitzei 18:2
מדור דור (שמות יז טז). אמר דוד אמר הקב"ה מדור דור ואנא בתריהון לדרי דרין, ר' אליעזר ור' יהושע ור' יוסי, ר' אליעזר אומר מדורו של משה, ועד דורו של שמואל, ר' יהושע אומר מדורו של שמואל, ועד דורו של מרדכי ואסתר, ור' יוסי אמר מדורו של מרדכי ואסתר, עד דורו של של מלך המשיח שהוא שלשה דורות, ומנין לדורו של מלך המשיח שהוא שלשה דורות, שנאמר ייראוך עם שמש ולפני ירח דור דורים (תהלים עב ה), דור חד, דורים שנים, הא תלתא. ר' ברכיה בשם ר' אבא בר כהנא [אמר] כל זמן שזרעו של עמלק קיים בעולם, כביכול כאילו כנף מכסה את הפנים, אבד זרעו של עמלק מן העולם, ניטלה הכנף, שנאמר ולא יכנף עוד (את) מוריד וגו' (ישעיה ל כ).