~か~ないかのうちに
Hardly had … when …; just as … (before it is even finished)
N2
V-dictionary / V-ta + か + (same verb) V-nai + かのうちに
~か~ないかのうちに says the second event happened almost at the same moment as the first, so close that one can hardly tell whether the first had finished. The same verb is repeated in the affirmative and the negative: {鳴|な}るか{鳴|な}らないかのうちに, {座|すわ}ったか{座|すわ}らないかのうちに. The second clause states something that actually happened, usually in the past, and cannot be the speaker's intention, an order or an invitation. It is close to ~たとたん and ~や{否|いな}や, but とたん stresses surprise, while this pattern stresses an extremely short, blurred gap. A common mistake is using two different verbs, or dropping の (か~ないうちに exists but is less formal).
Examples
始業のチャイムが鳴るか鳴らないかのうちに、ラインが動き始めた。
The start-of-shift chime had hardly sounded when the line started moving.
弁当を棚に並べたか並べないかのうちに、客が次々と手に取っていった。
No sooner had the bento boxes been put on the shelf than customers started picking them up one after another.
子どもは布団に入るか入らないかのうちに寝てしまった。
The child fell asleep almost the moment he got into the futon.
Exercises
1.電車のドアが開くか開かない 、乗客が一斉に降りてきた。
2.料理がテーブルに置かれるか置かれないかのうちに、 。