@@ -935,37 +935,39 @@ export abstract class AbstractMathDocument<N, T, D>
935935 * @override
936936 */
937937 public whenReady ( action : ( ) => any ) : Promise < any > {
938- return ( this . _readyPromise = this . _readyPromise . then ( ( ) => {
939- //
940- // Cache old _readyPromise and replace it with a resolved
941- // promise in case action() calls whenReady(), so we don't get
942- // a circular dependency where the action is waiting on itself.
943- //
944- const ready = this . _readyPromise ;
945- this . _readyPromise = Promise . resolve ( ) ;
946- //
947- // Do the action and save its result.
948- //
949- const result = action ( ) ;
950- //
951- // Get a promise that returns the result after
952- // any new _readyPromise resolves (in case action
953- // called whenReady() or another function that does).
954- //
955- const promise = this . _readyPromise . then ( ( ) => result ) ;
956- //
957- // Put back the original promise.
958- //
959- this . _readyPromise = ready ;
960- //
961- // Return promise that returns the result. The original
962- // _readyPromise will wait on it to complete before it resolves,
963- // since promises that return promises automatically chain.
964- // This inserts any new _readyPromise promises into the
965- // original _readyPromise chain at this point.
966- //
967- return promise ;
968- } ) ) ;
938+ return ( this . _readyPromise = this . _readyPromise
939+ . catch ( ( _ ) => { } )
940+ . then ( ( ) => {
941+ //
942+ // Cache old _readyPromise and replace it with a resolved
943+ // promise in case action() calls whenReady(), so we don't get
944+ // a circular dependency where the action is waiting on itself.
945+ //
946+ const ready = this . _readyPromise ;
947+ this . _readyPromise = Promise . resolve ( ) ;
948+ //
949+ // Do the action and save its result.
950+ //
951+ const result = action ( ) ;
952+ //
953+ // Get a promise that returns the result after
954+ // any new _readyPromise resolves (in case action
955+ // called whenReady() or another function that does).
956+ //
957+ const promise = this . _readyPromise . then ( ( ) => result ) ;
958+ //
959+ // Put back the original promise.
960+ //
961+ this . _readyPromise = ready ;
962+ //
963+ // Return promise that returns the result. The original
964+ // _readyPromise will wait on it to complete before it resolves,
965+ // since promises that return promises automatically chain.
966+ // This inserts any new _readyPromise promises into the
967+ // original _readyPromise chain at this point.
968+ //
969+ return promise ;
970+ } ) ) ;
969971 }
970972
971973 /**
0 commit comments