搜索插件、代码仓与 APP 分类

GitHub 代码仓dart-archive/clock

时钟

一个可伪造的 dart:core 时钟 API 包装器。

时钟 项目封面
星标
41
复刻
16
最近推送(UTC)
2024年10月28日
项目状态
已归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

[!IMPORTANT]
This repo has moved to https://github.com/dart-lang/tools/tree/main/pkgs/clock

Dart CI pub package package publisher

This package provides a Clock class which encapsulates the notion of the "current time" and provides easy access to points relative to the current time. Different Clocks can have a different notion of the current time, and the default top-level clock's notion can be swapped out to reliably test timing-dependent code.

For example, you can use clock in your libraries like this:

// run_with_timing.dart
import 'package:clock/clock.dart';

/// Runs [callback] and prints how long it took.
T runWithTiming<T>(T Function() callback) {
  var stopwatch = clock.stopwatch()..start();
  var result = callback();
  print('It took ${stopwatch.elapsed}!');
  return result;
}

...and then test your code using the fake_async package, which automatically overrides the current clock:

// run_with_timing_test.dart
import 'run_with_timing.dart';

import 'package:fake_async/fake_async.dart';
import 'package:test/test.dart';

void main() {
  test('runWithTiming() prints the elapsed time', () {
    FakeAsync().run((async) {
      expect(() {
        runWithTiming(() {
          async.elapse(Duration(seconds: 10));
        });
      }, prints('It took 0:00:10.000000!'));
    });
  });
}
Dart Archive GitHub avatar
GitHub 作者

Dart Archive ↗

Legacy projects kept around for posterity – See github.com/dart-lang for current work

语言Dart

使用的依赖

依赖清单 2 项

  • dart_flutter_team_lints开发依赖^3.0.0
  • test开发依赖^1.16.6

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗