Emulators are generally interested in tricking software written for multiple chip devices - from the point of view of the Z80 and best-selling devices, which you are probably talking about, at least about the graphics chip and the sound chip in addition to the processor.
In the real world, these chips operate simultaneously. There will be some kind of bus logic to allow them all to communicate, but they are otherwise in their own worlds.
Usually, you do not start emulating various chips as parallel processes, because the cost of forced execution of synchronization events is too high, especially in the general layout, where the same RAM block is used between several chips.
Thus, the easiest approach is the joint multitasking of various chips - run the Z80 for several cycles, then run the graphics chip in the same amount of time, etc. to infinity. What happens at start for n loops and return.
This is usually not an exact way to reproduce the behavior of a real computer bus, but it is easy to implement, and often you can trick most programs.
In the specific code that you posted, the author also decided that the emulation would cover the number of cycles until the end of the next whole instruction. Again, that is about ease of implementation, and not about what is connected with the actual interiors of a real machine. The number of running loops is returned, so other subsystems may try to adapt.
source share