PressureObserver Class
Observes the pressure of the sources of the device (https://w3c.github.io/compute-pressure/#the-pressureobserver-object), read from the PressureSourceProvider of the browsing context (ComputePressureOptions.Provider). Its callback is invoked from a task with the records queued since the previous call, while the document has the focus.
public sealed class PressureObserverConstructors
| Name | Description |
|---|---|
| PressureObserver(GlobalScope, PressureUpdateCallback) | Creates an observer of the pressure of a global object. |
| PressureObserver(PressureUpdateCallback) | Creates an observer of the pressure of the current global object (https://w3c.github.io/compute-pressure/#the-constructor-method). |
PressureObserver overloads
PressureObserver(GlobalScope, PressureUpdateCallback)
ComputePressure.csCreates an observer of the pressure of a global object.
public PressureObserver(GlobalScope global, PressureUpdateCallback callback)Parameters
globalGlobalScope- The window or the worker whose observer it is.
callbackPressureUpdateCallback- The callback invoked with the records of the changes.
PressureObserver(PressureUpdateCallback)
ComputePressure.csCreates an observer of the pressure of the current global object (https://w3c.github.io/compute-pressure/#the-constructor-method).
public PressureObserver(PressureUpdateCallback callback)Parameters
callbackPressureUpdateCallback- The callback invoked with the records of the changes.
See also
Properties
| Name | Description |
|---|---|
| KnownSources | Gets the source types supported by the user agent, in alphabetical order (https://w3c.github.io/compute-pressure/#the-knownsources-attribute). |
KnownSources
ComputePressure.csGets the source types supported by the user agent, in alphabetical order (https://w3c.github.io/compute-pressure/#the-knownsources-attribute).
public static IReadOnlyList<PressureSource> KnownSources { get; }Methods
| Name | Description |
|---|---|
| Disconnect() | Stops observing all the sources (https://w3c.github.io/compute-pressure/#the-disconnect-method): the queued records are removed. |
| Observe(PressureSource, PressureObserverOptions?) | Starts observing a source (https://w3c.github.io/compute-pressure/#the-observe-method). The task fails with a NotAllowedError DomException when a document of the global object is not allowed to use the compute-pressure feature, a NotSupportedError when the source is not supported by the PressureSourceProvider, and an AbortError when PressureObserver.Unobserve or PressureObserver.Disconnect is called before it completes. |
| TakeRecords() | Returns the queued records and empties the queue (https://w3c.github.io/compute-pressure/#the-takerecords-method). |
| Unobserve(PressureSource) | Stops observing a source (https://w3c.github.io/compute-pressure/#the-unobserve-method): its queued records are removed. |
Disconnect()
ComputePressure.csStops observing all the sources (https://w3c.github.io/compute-pressure/#the-disconnect-method): the queued records are removed.
public void Disconnect()Observe(PressureSource, PressureObserverOptions?)
ComputePressure.csStarts observing a source (https://w3c.github.io/compute-pressure/#the-observe-method). The task fails with a NotAllowedError DomException when a document of the global object is not allowed to use the compute-pressure feature, a NotSupportedError when the source is not supported by the PressureSourceProvider, and an AbortError when PressureObserver.Unobserve or PressureObserver.Disconnect is called before it completes.
public Task Observe(PressureSource source, PressureObserverOptions? options = null)Parameters
sourcePressureSource- The observed source.
optionsPressureObserverOptions?- The requested sample interval.
Returns
See also
TakeRecords()
ComputePressure.csReturns the queued records and empties the queue (https://w3c.github.io/compute-pressure/#the-takerecords-method).
public IReadOnlyList<PressureRecord> TakeRecords()Unobserve(PressureSource)
ComputePressure.csStops observing a source (https://w3c.github.io/compute-pressure/#the-unobserve-method): its queued records are removed.
public void Unobserve(PressureSource source)