Skip to content

Commit

Permalink
Fix documentation: Options to observe method (#260)
Browse files Browse the repository at this point in the history
Also fix leftovers from sampleRate to sampleInterval.
Fixes #259
  • Loading branch information
arskama committed Apr 5, 2024
1 parent 41ec61b commit 849e89a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
23 changes: 22 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ function pressureCallback(update) {
}
}

const observer = new PressureObserver(pressureCallback, { sampleInterval : 1000 });
const observer = new PressureObserver(pressureCallback, { sampleInterval : 1_000 });
observer.observe('cpu');
```
### After (Release in Chrome M125)

sampleRate was renamed to sampleInterval and changed from Hz to ms.[issue #253](https://github.com/w3c/compute-pressure/issues/253);
Options are moved to the observe method. [issue #259] (https://github.com/w3c/compute-pressure/issues/259);


[The explainer](https://github.com/w3c/compute-pressure/blob/main/README.md) and
[specification](https://www.w3.org/TR/compute-pressure/) capture the latest vision for the API,
implemented for further experimentation.

```js
function pressureCallback(update) {
if (update.status === "critical") {
// Dramatically cut down compute requirements to avoid overheating.
return;
}
}

const observer = new PressureObserver(pressureCallback);
observer.observe('cpu', { sampleInterval : 1_000 });
```
4 changes: 2 additions & 2 deletions HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ function pressureObserverCallback(updates) {
}

// Create observer with 1000ms sample interval.
observer = new PressureObserver(pressureObserverCallback, { sampleInterval: 1000 });
observer = new PressureObserver(pressureObserverCallback);

// Start observer.
await observer.observe("cpu");
await observer.observe("cpu", { sampleInterval: 1_000 });
```

You should see, everytime the state changes, the following:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ function callback(entries) {
console.log(`Current pressure ${lastEntry.state}`);
}

const observer = new PressureObserver(callback, { sampleInterval: 1000 }); // 1000ms
await observer.observe("cpu");
const observer = new PressureObserver(callback);
await observer.observe("cpu", {sampleInterval: 1_000 }); // 1000ms
```

## Key scenarios
Expand Down Expand Up @@ -356,8 +356,8 @@ function pressureChange(entries) {
}
}

const observer = new PressureObserver(pressureChange, { sampleInterval: 1000 });
await observer.observe("cpu");
const observer = new PressureObserver(pressureChange);
await observer.observe("cpu", { sampleInterval: 1_000 });
```

## Detailed design discussion
Expand Down

0 comments on commit 849e89a

Please sign in to comment.