Mono-MultiTasking

I’m making an editor for roland ZenCore synths (Fantom, Ax Edge, JupiterX / Xm) and I have a problem that I don’t know if it can be solved.
For the analysis of the midi messages received by PC from synth I use the function
midiMessageReceived = function (midiMessage) which is called in the main panel in “Called when a a panel receives a MIDI Message.

I’m creating UI buttons that call functions through the classic “Called when the Modulator value Change”.
Let’s take for example a function that does two operations

1) asks the synth to send one of the SYSEX midi messages
2) stores data on file

the problem I have is that the order I would like is not respected, that is:
a) I ask the synth to send SYSEX midi messages
b) the synth sends the messages and midiMessageReceived = function (midiMessage) performs its task
c) I store the data

what happens is that after I ask the synth to send one of the SYSEX midi messages, the data is first stored on file and only after unction is finished , the midiMessageReceived = function (midiMessage) does its task.

Is there no way to get the requested a-b-c order?
https://www.youtube.com/watch?v=-p2vKKN25GQ

Ctrlr