Test whether the queue is empty

70 views
Skip to first unread message

Daniel

unread,
Feb 2, 2017, 7:02:32 AM2/2/17
to MathJax Users
After adding to the queue via MathJax.Hub.Queue(...) how can I test whether everything on the queue is already processed or not?

Also, it seems to me this should be easy to find in the documentation but it wasn't for me. Maybe you can give me a hint where to find answers to such questions.

Best,
Daniel

Davide Cervone

unread,
Feb 15, 2017, 10:14:05 AM2/15/17
to mathja...@googlegroups.com
There is no API for checking this, but you can queue another function that can be used to tell you when the previous material is completed.  For example:

var isDone = false;
MathJax.Hub.Queue(
  ["Typeset",MathJax.Hub],
  function () {isDone = true}
);

You can then use 

if (isDone) {
  // MathJax typesetting complete
} else {
  // MathJax typesetting still going on
}

to tell if MathJax is still running.  You can use this technique, for example, to prevent additional Typeset calls fun being queued until the previous is completed, and then start a new one at that point if you would have queued one during the previous typeset.  Something like

var isTypesetting = false, typesetNeeded = false;
function Typeset() {
  if (isTypesetting) {
    typesetNeeded = true;
  } else {
    isTypesetting = true;
    MathJax.Hub.Queue(
      ["Typeset",MathJax.Hub],
      TypesetFinished
    );
  }
}
function TypesetFinished() {
  isTypesetting = false;
  if (typesetNeeded) {
    typesetNeeded = false;
    Typeset();
  }
}

should do the trick (though the code above is untested, but it should get you the right idea).  Calls to Typeset() will not queue more than on typeset operation at a time, and will call Typeset again at the end if requests to Typeset() occurred while one typesetting operation was in progress.

Perhaps that will do what you need.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages