B2G/gecko/toolkit/components/places/tests/head_common.js
/**
 * Waits for a frecency update then calls back.
 *
 * @param aURI
 *        URI or spec of the page we are waiting frecency for.
 * @param aValidator
 *        Validator function for the current frecency. If it returns true we
 *        have the expected frecency, otherwise we wait for next update.
 * @param aCallback
 *        function invoked when frecency update finishes.
 * @param aCbScope
 *        "this" scope for the callback
 * @param aCbArguments
 *        array of arguments to be passed to the callback
 *
 * @note since frecency is something that can be changed by a bunch of stuff
 *       like adding and removing visits, bookmarks we use a polling strategy.
 */
Waits for a frecency update then calls back.
@param aURI
URI or spec of the page we are waiting frecency for.
@param aValidator
Validator function for the current frecency. If it returns true we
have the expected frecency, otherwise we wait for next update.
@param aCallback
function invoked when frecency update finishes.
@param aCbScope
"this" scope for the callback
@param aCbArguments
array of arguments to be passed to the callback

@note since frecency is something that can be changed by a bunch of stuff
like adding and removing visits, bookmarks we use a polling strategy.
Waits for a frecency update then calls back . @param aURI URI or spec of the page we are waiting frecency for . @param aValidator Validator function for the current frecency . If it returns true we have the expected frecency otherwise we wait for next update . @param aCallback function invoked when frecency update finishes . @param aCbScope " this " scope for the callback @param aCbArguments array of arguments to be passed to the callback @note since frecency is something that can be changed by a bunch of stuff like adding and removing visits bookmarks we use a polling strategy .
function waitForFrecency(aURI, aValidator, aCallback, aCbScope, aCbArguments) {
  Services.obs.addObserver(function (aSubject, aTopic, aData) {
    let frecency = frecencyForUrl(aURI);
    if (!aValidator(frecency)) {
      print("Has to wait for frecency...");
      return;
    }
    Services.obs.removeObserver(arguments.callee, aTopic);
    aCallback.apply(aCbScope, aCbArguments);
  }, "places-frecency-updated", false);
}
function waitForFrecency ( aURI , aValidator , aCallback , aCbScope , aCbArguments ) { Services . obs . addObserver ( function ( aSubject , aTopic , aData ) { let frecency = frecencyForUrl ( aURI ) ; if ( ! aValidator ( frecency ) ) { print ( "Has to wait for frecency..." ) ; return ; } Services . obs . removeObserver ( arguments . callee , aTopic ) ; aCallback . apply ( aCbScope , aCbArguments ) ; } , "places-frecency-updated" , false ) ; }
Waits for a frecency update then calls back.
Waits for a frecency update then calls back .