In reply to hvalec:
I’m not sure what kind of better solution you’re looking for.
Your code has a delta cycle glitch. a_reg and data_reg are being updated in two different active event regions. Your solution samples pulse_done so it ignores the glitch it has. Note that $monitor or VCD $dumpvars do not show glitches.