〜か〜ないかのうちに
almost before, the very moment
Verb dictionary form + か + same verb ない-form + かのうちに
Sign up free to review this point on a spaced schedule.
か〜ないかのうちに says the second thing happened so quickly that the first had barely finished, or barely begun: ベルが鳴るか鳴らないかのうちに、学生たちは教室を出た, "the bell had barely started ringing when the students left".
Say the verb twice, first in the dictionary form and then in the ない-form: 座るか座らないか, 明けるか明けないか. The literal sense is "while it's unclear whether it happened or not".
The second half is a past event, usually something someone did quickly or eagerly. It's a vivid, descriptive pattern, common in stories.
The meaning overlaps with たとたん and と同時に, but it stresses how incredibly fast it was.
Examples
ベルが鳴るか鳴らないかのうちに、学生たちは教室を出た。
The bell had barely started ringing when the students left the classroom.
横になるかならないかのうちに、眠ってしまった。
I fell asleep almost the moment I lay down.
席に座るか座らないかのうちに、電車が動き出した。
The train started moving before I'd even sat down.
夜が明けるか明けないかのうちに、出発した。
We set off just as dawn was breaking.
彼は話を聞き終わるか終わらないかのうちに、部屋を飛び出した。
He dashed out of the room before he'd even finished hearing the story.