The past anterior

The Spanish past anterior—as well as the pluperfect—resembles the English past perfect, yet it indicates a previous passed situation clearly limited as immediate to another that has also passed. The limiting expressions used are apenas, cuando, después que, después de que, en cuanto, luego que, una vez, una vez que and a few others.  The past anterior is formed by using the preterit of the verb haber  + the past participle of the verb that describes the action or state. Currently, other verb tenses can be used to express this verb paradigm, so it is only used in formal writing.

En cuanto hubimos terminado el examen, sonó la alarma.