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/. */
7 var EXPORTED_SYMBOLS = ["Observer"];
9 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
12 static observe(type, observer) {
13 Services.obs.addObserver(observer, type);
16 static unobserve(type, observer) {
17 Services.obs.removeObserver(observer, type);
20 static once(type, observer = () => {}) {
21 return new Promise(resolve => {
22 const wrappedObserver = (first, ...rest) => {
23 Observer.unobserve(type, wrappedObserver);
24 observer.call(first, ...rest);
27 Observer.observe(type, wrappedObserver);