no sooner ... than ...; as soon as
Fixed expression attaching to the plain form of a verb. Emphasizes that the second action happens immediately after the first, often with a sense of urgency or surprise. Common in written and formal spoken Japanese.
彼は家に着くが早いか、また出かけてしまった。
No sooner had he arrived home than he went out again.
ベルが鳴るが早いか、生徒たちは教室を飛び出した。
As soon as the bell rang, the students rushed out of the classroom.
Also means 'just as' or 'the moment', but 途端に follows the past tense of a verb (~た途端に), whereas が早いか follows the plain form.
The expression combines the particle が with 早い (fast, early) and the question particle か, literally meaning 'is it fast?'. It has become a fixed pattern meaning 'no sooner than'.