-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Move plotly.animate to Lib.syncOrAsync #1693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Okay, it passes the tests. That's the first big step. That means it's worth inventing a test. I'll just be creative. |
I've added a test, but the conclusion is that most of the work was ending up on the main plotly queue anyway via Which is to say, what I thought I was implementing here was already happening correctly so that I'm not quite sure what this PR does do beyond adding some redundancy and moving a couple extra lines into the promise queue. |
Okay here's my conclusion on this PR: I can't find a problem it solves. Plotly.plot(...)
Plotly.animate(...)
Plotly.addFrames(...) instead of: Plotly.plot(...).then(() => {
return Plotly.addFrames(...)
}).then(() => {
return Plotly.animate(...)
}) So in the end I don't really have a strong preference on whether to merge this or not. I think it comes down to a matter of conventions instead of cases that succeed/fail. My question then is: Should plotly.js API functions do any setup when invoked, or should everything be wrapped in |
@rreusser there's not all that much that plotly.js does async, so it's not surprising that you can't pin this down. Mathjax rendering, Note that If your goal is to wait for the plot to finish anything else it's been doing - which I think is a good goal, and probably important in some cases (a map or a plot with mathjax that animates on load?) then I think you just need to add return Lib.syncOrAsync([
Plots.previousPromises, // only async if there *are* promises in the queue
function() {
return new Promise(...)
}
], gd); // gd is just passed along to previousPromises, it's not needed for your own fn then if everything is sync, |
Thanks for the clarification, @alexcjohnson! Is there a rule of thumb on which API functions should wait for previousPromises to finish? Like it's possible to write a synchronous-looking API that queues everything internally and is actually asynchronous, but I'm not sure if that's a good or bad goal. My specific concern is that API commands would get interleaved inside the async parts of |
Offhand I'd say anything that can modify the plot should wait for
Are you talking about |
That is it, as far as I know. Shout-out to #76 🔈
👍 |
Makes sense, though... what would happen if you purge with promises still pending? I guess the hope would be that it just throws an error inside the callback, which doesn't affect anything in the wider app... or perhaps it can still act on the now-removed plot elements and doesn't even throw an error? I guess mostly it will be fine but perhaps there are cases this would pollute |
Closing. It's probably best to find a scenario where not using Now part #933 |
This PR moves the content of
Plotly.animate
intoLib.syncOrAsync
so that it better fits into the plotly queue. The particular use-case isPlotly.restyle
andPlotly.animate
called in synchronous series (i.e. not promise-chained), though I'm currently unable to produce a situation that actually triggers any problems. I stumbled upon the possibility of a problem while working on the notifier, and solved things just by properlythen
-ing all the plotly API calls. That's good practice anyway, but this is also probably the right way for things to be.I'm not quite sure how to produce a test case for this (short of inspecting the promise queue, except those are just anonymous callbacks, right?), but I'm glad to try if someone can come up with an idea that's not inherently fragile due to a race condition.
Additional note: there are only ~240 lines due to an indentation change. I've only changed this:
into this
/cc @alexcjohnson @etpinard