1 |
- {"ast":null,"code":"import { Observable } from \"./observable.js\";\n/**\n * A wrapper for the experimental pressure api which allows a callback to be called whenever certain thresholds are met.\n */\nexport class PressureObserverWrapper {\n /**\n * A pressure observer will call this callback, whenever these thresholds are met.\n * @param options An object containing the thresholds used to decide what value to to return for each update property (average of start and end of a threshold boundary).\n */\n constructor(options) {\n this._observer = null;\n this._currentState = [];\n /**\n * An event triggered when the cpu usage/speed meets certain thresholds.\n * Note: pressure is an experimental API.\n */\n this.onPressureChanged = new Observable();\n if (PressureObserverWrapper.IsAvailable) {\n this._observer = new PressureObserver(update => {\n this._currentState = update;\n this.onPressureChanged.notifyObservers(update);\n }, options);\n }\n }\n /**\n * Returns true if PressureObserver is available for use, false otherwise.\n */\n static get IsAvailable() {\n return typeof PressureObserver !== \"undefined\" && PressureObserver.knownSources && PressureObserver.knownSources.includes(\"cpu\");\n }\n /**\n * Method that must be called to begin observing changes, and triggering callbacks.\n * @param source defines the source to observe\n */\n observe(source) {\n try {\n var _this$_observer;\n (_this$_observer = this._observer) === null || _this$_observer === void 0 || _this$_observer.observe(source);\n this.onPressureChanged.notifyObservers(this._currentState);\n } catch {\n // Ignore error\n }\n }\n /**\n * Method that must be called to stop observing changes and triggering callbacks (cleanup function).\n * @param source defines the source to unobserve\n */\n unobserve(source) {\n try {\n var _this$_observer2;\n (_this$_observer2 = this._observer) === null || _this$_observer2 === void 0 || _this$_observer2.unobserve(source);\n } catch {\n // Ignore error\n }\n }\n /**\n * Release the associated resources.\n */\n dispose() {\n var _this$_observer3;\n (_this$_observer3 = this._observer) === null || _this$_observer3 === void 0 || _this$_observer3.disconnect();\n this._observer = null;\n this.onPressureChanged.clear();\n }\n}","map":{"version":3,"names":["Observable","PressureObserverWrapper","constructor","options","_observer","_currentState","onPressureChanged","IsAvailable","PressureObserver","update","notifyObservers","knownSources","includes","observe","source","_this$_observer","unobserve","_this$_observer2","dispose","_this$_observer3","disconnect","clear"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/pressureObserverWrapper.js"],"sourcesContent":["import { Observable } from \"./observable.js\";\n/**\n * A wrapper for the experimental pressure api which allows a callback to be called whenever certain thresholds are met.\n */\nexport class PressureObserverWrapper {\n /**\n * A pressure observer will call this callback, whenever these thresholds are met.\n * @param options An object containing the thresholds used to decide what value to to return for each update property (average of start and end of a threshold boundary).\n */\n constructor(options) {\n this._observer = null;\n this._currentState = [];\n /**\n * An event triggered when the cpu usage/speed meets certain thresholds.\n * Note: pressure is an experimental API.\n */\n this.onPressureChanged = new Observable();\n if (PressureObserverWrapper.IsAvailable) {\n this._observer = new PressureObserver((update) => {\n this._currentState = update;\n this.onPressureChanged.notifyObservers(update);\n }, options);\n }\n }\n /**\n * Returns true if PressureObserver is available for use, false otherwise.\n */\n static get IsAvailable() {\n return typeof PressureObserver !== \"undefined\" && PressureObserver.knownSources && PressureObserver.knownSources.includes(\"cpu\");\n }\n /**\n * Method that must be called to begin observing changes, and triggering callbacks.\n * @param source defines the source to observe\n */\n observe(source) {\n try {\n this._observer?.observe(source);\n this.onPressureChanged.notifyObservers(this._currentState);\n }\n catch {\n // Ignore error\n }\n }\n /**\n * Method that must be called to stop observing changes and triggering callbacks (cleanup function).\n * @param source defines the source to unobserve\n */\n unobserve(source) {\n try {\n this._observer?.unobserve(source);\n }\n catch {\n // Ignore error\n }\n }\n /**\n * Release the associated resources.\n */\n dispose() {\n this._observer?.disconnect();\n this._observer = null;\n this.onPressureChanged.clear();\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,CAAC;EACjC;AACJ;AACA;AACA;EACIC,WAAWA,CAACC,OAAO,EAAE;IACjB,IAAI,CAACC,SAAS,GAAG,IAAI;IACrB,IAAI,CAACC,aAAa,GAAG,EAAE;IACvB;AACR;AACA;AACA;IACQ,IAAI,CAACC,iBAAiB,GAAG,IAAIN,UAAU,CAAC,CAAC;IACzC,IAAIC,uBA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