In his letter, James encourages prayer. Not just prayer, but effective prayer.
He addresses two issues that block prayer. The first is sin. We all experience the presence of sin, and failure to keep God's word. No one will be perfect in this life. The issue comes when we hang onto sin. Sin causes a breakdown in our relationship with God. His heart is still for us. But sin blocks God from expressing his love to us, and four us. If we turn from sin, are honest with wrong we commit, and turn our hearts back to God, he turns his heart back to us.
And if we lean into him with faith, God's heart is to respond t faith. The example James uses is Elijah praying for rain. Because of the wickedness of the king, Elijah prays for no rain. And it stops raining for several years. Then, he prays for rain, and there is a deluge. There is a lot of confusion about God's timing, especially as we see God sometimes respond immediately, and sometimes respond after a long time.
There is a story about a man, who prayed for the salvation of his friends. While he was alive, none of his friends chose to follow Jesus. Then, he died, and all of his friends decided to follow Jesus.
God always responds in his wisdom. God always responds with a heart of love. Our part is to keep trusting, keep praying, and remain patient.