tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

head.js (698B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* exported waitUntilState */
      6 
      7 "use strict";
      8 
      9 const { require } = ChromeUtils.importESModule(
     10  "resource://devtools/shared/loader/Loader.sys.mjs"
     11 );
     12 
     13 function waitUntilState(store, predicate) {
     14  return new Promise(resolve => {
     15    const unsubscribe = store.subscribe(check);
     16    function check() {
     17      if (predicate(store.getState())) {
     18        unsubscribe();
     19        resolve();
     20      }
     21    }
     22 
     23    // Fire the check immediately incase the action has already occurred
     24    check();
     25  });
     26 }