PySide2/PyQt5 QApplication processEvents() equivalent in Blender API?

in PySide2/PyQt5 there is a very useful function that forces all pending events to be processed. Be it for example any GUI repaints, data update, etc. Im looking for something similar in Blender.

Im doing this at some point in the code:

bpy.context.window.workspace = self.get_scripting_workspace()
context_window = bpy.context.window

but the context_window is never updated and still remains to be “Layout”.

How can i update the datablocks forcibly by code? is there the possibility?

Thanks in advance!

Changing context during event handling (like operator execution) is often problematic, like in the case of workspaces. Event handling relies heavily on the context, changing that in-between would have ugly consequences.
So the workspaces have to be changed in a delayed fashing, basically before the next redraw.