N1
なり
As soon as, The moment, When
息子が家に上がるなりトイレへと駆け込んだ。
My son ran to the toilet as soon as he entered the house.
Explanation
「Vるなり」 means 'the moment V happens, ...'. As soon as the first act occurs, the same person does the next with no gap, and the second act is often unexpected or abrupt. 「部屋に入るなり、倒れ込んだ」 (He collapsed the moment he entered the room), 「電話を切るなり、飛び出していった」 (As soon as he hung up, he rushed out). Both acts are by the same third person; you cannot use 'I', so not 「私は帰るなりテレビを見た」. A passive ending for something done to the speaker is fine: 「彼に会うなり罵られた」 (He swore at me the moment I saw him). The ending is a past fact, never an intention, command, guess or wish.
Mixed up with
「が早いか」: the second act jumps in just as the first begins; very hurried.
「や否や」: the second follows in the instant the first finishes; more like objective reporting.
「なり」: the same third person does something, often unexpected, right after the first act.
「そばから」: the same bad cycle repeats, like forgetting as fast as you learn.