The processing thread counted the remaining time down in 1000 ms steps and read
the global CurrentProgress on every wake, which caused two problems.
Any duration that is not a whole number of seconds finished late, since the
thread only checked after another full second. The NUI bar runs on wall clock
time, so the bar completed and the player then stood frozen waiting for onFinish.
Cancelling did not stop the thread either. CancelProgressbar clears
CurrentProgress, but the sleeping thread only notices up to a second later, and if
a new bar was started in that window it saw a non-nil CurrentProgress and kept
decrementing the new one alongside its own thread. The new bar then finished at
roughly half its length, firing onFinish early.
The run now carries an id, so a thread stops as soon as its run is no longer the
current one, and the end is an absolute timestamp rather than a countdown.
Measured in game on artifact 25770, requested versus actual onFinish:
before: 500 -> 1011, 4200 -> 5042, cancel then 3000 -> 1427
after: 500 -> 519, 4200 -> 4222, cancel then 3000 -> 3058
Personally, I think this feature should have been here a long time ago. I hope that adding this code will help players in the future and if anyone here has a suggestion for a code change feel free to comment.