Constrain/snap vertices to each other while updating real time in UI

Hi,

Would anyone know if it is possible to constrain/snap two vertices to each other and update this continuously?

Ideally in my code this would work best somewhat like:

cube = bpy.data.objects["Cube"]

for vertex in bpy.context.active_object.data.vertices:
    cube.data.vertices[0].co = vertex[0].co

And then if possible make this code run in the background so it updates when the first vertex in the active object is translated.

I’ve looked into using the modal operator, but I couldn’t really get it to work in any other way then to pause the entire UI until the modal operator returns “finished” or “cancelled”.