So this guy mentions Chekhov's gun, and he says when foreshadowing something then the thing that's foreshadowed need to happen before the end of the story. So while putting it at the beginning of the story makes sense, I am wondering if we can foreshadow it right before, and when it is too soon to the event that's foreshadowed? Obviously, if something is foreshadowed 3 paragraph before the event happens that's probably too soon, but is there a cutoff line of sort?
The only rule about foreshadowing is that it has to leave the reader, looking back from the event foreshadowed, thinking that makes sense after all. That it's not a deus ex machina.
The problem with foreshadowing it right before it that it looks like you are aware of the problem and trying to patch it. Having one character meet a second and then tell a third he's untrustworthy just before he betrays them without warning -- though it might if it was established earlier than the second character seems to never be in the right place to meet the first, so that the reader sees there might be a reason for the avoidance.