Remove indirection in Timer example

The example was originally written without a `main`, and with an example
using `Duration.operator *`. An update added a call to the example
method from a new `main`, removed the usage of `Duration.operator *`,
but did not remove the prose reference.

- Remove the sentence mentioning that the duration can be const or
  computed.
- Remove the intermediate `scheduleTimeout` method, move the `Timer`
  construction to `main`. This removes any consideration of `Duration`
  vs `int milliseconds` which had been added in an attempt make the docs
  more focused on `Timer` than `Duration`.

R=lrn@google.com

CoreLibraryReviewExempt:Documentation change.
Change-Id: I26bb4e12910eb50cf5975b8a6573701a5a862070
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330980
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
This commit is contained in:
Nate Bosch 2023-10-19 18:26:49 +00:00 committed by Commit Queue
parent a3c423237f
commit d7af8ef846

View file

@ -13,17 +13,11 @@ part of dart.async;
/// A negative duration is treated the same as a duration of 0.
/// If the duration is statically known to be 0, consider using [run].
///
/// Frequently the duration is either a constant or computed as in the
/// following example (taking advantage of the multiplication operator of
/// the [Duration] class):
/// ```dart
/// void main() {
/// scheduleTimeout(5 * 1000); // 5 seconds.
/// Timer(const Duration(seconds: 5), handleTimeout);
/// }
///
/// Timer scheduleTimeout([int milliseconds = 10000]) =>
/// Timer(Duration(milliseconds: milliseconds), handleTimeout);
///
/// void handleTimeout() { // callback function
/// // Do some work.
/// }