Sequence of hangup handlers

Situation:

A → inbound call (= channel1) → asterisk → outbound call( = channel2) → B
On channel1 is hanguphandler1
On channel2 is hanguphandler2

If B does a hangup of the call, the hanguphandler2 is processed first and hanguphandler1 is processed afterwards.

If A does a hangup of the call, the hanguphandler1 is processed first and hanguphandler2 is processed afterwards.

Problem:

What can I do to have always processed the hanguphandler2 first and hanguphandler 1 last.

There is no built in synchronization or link between the two hangup handlers. It ultimately depends on when the channel hangs up. Relying on some kind of ordering there would likely be prone to issues.