Closed caewok closed 2 years ago
I doubt this is directly related to libWrapper - all libWrapper does is detect a Promise, and if it is one it then delays the cleanup with a then
call. Essentially, all Promise-related code is delegated to the callee/caller.
Every single unit/integration test in the suite will run both with async and not-async code paths (and randomised settlement delays), so this code should be well exercised.
The relevant libWrapper code can be found in https://github.com/ruipin/fvtt-lib-wrapper/blob/master/src/lib/wrapper.js#L480-L496
My immediate suspicion is the fact that Drag Ruler seems to be calling wrapped
multiple times inside its animateToken
wrapper, and then waiting for the Promises to settle in parallel:
await
ing them individually resolve the issue?animateToken
.If it is indeed the browser breaking the Promise resolution order for whatever reason, you might need to detect an on-going animation, and automatically settle/cancel the previous Promises (or ensure your new Promises are a then
of the previous ones).
See for example how Token-Animation-Tools does the animation cancellation: https://github.com/ruipin/fvtt-token-animation-tools/blob/master/token-animation-tools.js#L168-L193
That said, I would suggest a few things that could allow us to remove libWrapper from the equation:
Closing since I believe this has been answered, and there have been no further replies in over two months. Feel free to re-open if you wish to continue the discussion.
Confirm you have read the above I am the libRuler developer. I am working on a fork of Drag Ruler that uses libRuler, and I am having an issue that may be related to libWrapper and async, but I am not sure. This is bit involved for a discord question and is rather libWrapper-specific, so I thought I would try here instead.
Setup Foundry 0.8.9 libWrapper 1.10.5.0 Drag Ruler fork: https://github.com/caewok/foundryvtt-drag-ruler/tree/caewok-libruler libRuler: https://github.com/caewok/fvtt-lib-ruler
Describe the question When dragging one or more tokens, I am seeing instances where the token moves places it should not. Sometimes, the token ends up at a different location than expected (usually seen with groups, where the group starts in a tight square and ends up spread out). Sometimes, the token drifts and then jumps back to a position. This, to me, suggests a problem with how async is being used to update token positions.
I reviewed issue #7 and have tried various versions of the following code, but this problem still persists. So I was hoping that you might have some insight into what might be going wrong here.
Code flow I think what should be happening is:
moveToken
calls the wrappedmoveToken
and awaits -->moveToken
callsanimateToken
and awaits -->animateToken
runs. For each selected token:animateToken
is called.animateToken
awaits Foundry base functionstoken.document.update
andtoken.animateMovement
.Additional context Sorry, this will be somewhat involved in order to explain relevant the code steps...
libRuler overrides Ruler.prototype.moveToken:
The key part of the override for this issue, I think, is where the libRuler version iterates through the ruler segments (lines between ruler waypoints), and calls a new method,
animateToken
:libRuler adds to the new method to the Ruler class :
Now, Drag Ruler wraps
moveToken
andanimateToken
:Drag Ruler wraps
moveToken
because until the dragged token is let go, no actual movement should happen. The relevant portion is:Drag Ruler wraps
animateToken
so it can handle adjustments for dragging multiple tokens. The relevant portion is: