mozilla/pdf.js — pull request #3341 by Snuffleupagus (2013-06-05 22:34:30+00:00)
Title: Tweak the behaviour of navigateTo during document load

When I fixed issue #3068 in #3135, it was done by waiting for all pages to be resolved before the `navigateTo` method would be run.
Unfortunately this approach has at least two unwanted side effects. First of all, the loading of a destination from an `initialBookmark` is forced to wait for the entire document to load, even when it's not necessary. Secondly, the more severe issue is that until the document has finished loading, clicking on links within the document will not produce any results until the document is completely loaded. This can thus create the impression that links are broken in pdf.js.
Both these issues are particular noticeable in large and/or slow loading documents.

I've tried to address the above issues by adding a Promise to the `navigateTo` method, that will be resolved as soon as all the necessary info is loaded. In my testing, especially for larger files this cuts down the waiting time when are clicked considerably.
To prevent dealing with a miniature callback hell, I've implemented this in such a way that if a destination is currently unresolved when a new link is clicked, the previous one will simply be discarded.

Since I don't have a great deal of experience working with promises, I hope that this approach is sound!