Skip to content

Commit 423f751

Browse files
authored
Merge pull request #40 from fitzgen/console-timer-fixups
Little things for `console-timer`
2 parents 3d26cd4 + c61a75b commit 423f751

File tree

1 file changed

+7
-5
lines changed
  • crates/console-timer/src

1 file changed

+7
-5
lines changed

crates/console-timer/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Additionally, these measurements will show up in your browser's profiler's
1313
This API wraps both the `time` and `timeEnd` calls into a single type
1414
named `ConsoleTimer`, ensuring both are called.
1515
16-
## Scoped measurement
16+
## Scoped Measurement
1717
1818
Wrap code to be measured in a closure with `ConsoleTimer::scope`.
1919
@@ -26,7 +26,7 @@ let value = ConsoleTimer::scope("foo", || {
2626
});
2727
```
2828
29-
## RAII-style measurement
29+
## RAII-Style Measurement
3030
3131
For scenarios where `ConsoleTimer::scope` can't be used, like with
3232
asynchronous operations, you can use `ConsoleTimer::new` to create a timer.
@@ -36,12 +36,14 @@ The measurement ends when the timer object goes out of scope / is dropped.
3636
use gloo_console_timer::ConsoleTimer;
3737
use gloo_timers::Timeout;
3838
39+
// Start timing a new operation.
40+
let timer = ConsoleTimer::new("foo");
41+
42+
// And then asynchronously finish timing.
3943
let timeout = Timeout::new(1_000, move || {
40-
let _timer = ConsoleTimer::new("foo");
41-
// Do some work which will be measured
44+
drop(timer);
4245
});
4346
```
44-
4547
*/
4648

4749
#![deny(missing_docs, missing_debug_implementations)]

0 commit comments

Comments
 (0)