, frequently seen using its kanji form た途端（とたん）に
is a structure used to convey that something happens 'the instant', or 'the moment' that something else occurs. It is a combination of the auxiliary verb
た (indicating the completion of a verb), and the noun
途端（とたん） 'on the tip of' used adverbially (with に
(B) is used to express (B) things that are beyond the control of the speaker, and may be considered strange, or unexpected.
The moment I got on the highway, my tire got punctured.
The moment I got into my futon, I received a call from my senpai.
As 途端（とたん） literally means 'on the tip of', any (B) action is considered to happen either directly upon (A), or even simultaneously with (A).