Skip to content

Commit

Permalink
Micro updates to documentations and infra (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfccp authored Feb 4, 2025
1 parent 687955b commit af0ea71
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 152 deletions.
10 changes: 0 additions & 10 deletions .codecov.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check-dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
# Current supported major
major: 3
# Latest minor that we are explicitly supporting
latest_minor: 5
latest_minor: 6

jobs:
check-dart-version:
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
dart_version: ["3.0", "3.1", "3.2", "3.3", "3.4", "3.5"]
dart_version: ["3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6"]

runs-on: ubuntu-latest

Expand All @@ -37,15 +37,3 @@ jobs:

- name: Run tests
run: $(command -v pub || echo dart pub) run test --coverage=./coverage

- name: Convert coverage to LCOV
run: $(command -v pub || echo dart pub) run coverage:format_coverage
--lcov --packages=.dart_tool/package_config.json --report-on=lib
-i coverage -o coverage/lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage/lcov.info
flags: unit,dart${{ matrix.dart_version }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.dart_tool/
.packages
build/

# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

Expand Down
141 changes: 15 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,138 +1,27 @@
# pausable\_timer

[![CI](https://github.com/llucax/pausable_timer/workflows/CI/badge.svg)](https://github.com/llucax/pausable_timer/actions?query=branch%3Amain+workflow%3ACI+)
[![Pub Score](https://github.com/llucax/pausable_timer/workflows/Pub%20Score/badge.svg)](https://github.com/llucax/pausable_timer/actions?query=branch%3Amain+workflow%3A%22Pub+Score%22+)
[![Latest Dart version](https://github.com/llucax/pausable_timer/actions/workflows/check-dart.yaml/badge.svg)](https://github.com/llucax/pausable_timer/actions/workflows/check-dart.yaml)
[![Coverage](https://codecov.io/gh/llucax/pausable_timer/branch/main/graph/badge.svg)](https://codecov.io/gh/llucax/pausable_timer)
[![CI](https://github.com/mateusfccp/pausable_timer/workflows/CI/badge.svg)](https://github.com/mateusfccp/pausable_timer/actions?query=branch%3Amain+workflow%3ACI+)
[![Pub Score](https://github.com/mateusfccp/pausable_timer/workflows/Pub%20Score/badge.svg)](https://github.com/mateusfccp/pausable_timer/actions?query=branch%3Amain+workflow%3A%22Pub+Score%22+)
[![Latest Dart version](https://github.com/mateusfccp/pausable_timer/actions/workflows/check-dart.yaml/badge.svg)](https://github.com/mateusfccp/pausable_timer/actions/workflows/check-dart.yaml)
[![pub package](https://img.shields.io/pub/v/pausable_timer.svg)](https://pub.dev/packages/pausable_timer)
[![pub points](https://img.shields.io/pub/points/pausable_timer)](https://pub.dev/packages/pausable_timer/score)
[![popularity](https://img.shields.io/pub/popularity/pausable_timer)](https://pub.dev/packages/pausable_timer/score)
[![likes](https://img.shields.io/pub/likes/pausable_timer)](https://pub.dev/packages/pausable_timer/score)
[![Sponsor (llucax)](https://img.shields.io/badge/-Sponsor%20(llucasx)-555555?style=flat-square)](https://github.com/llucax/llucax/blob/main/sponsoring-platforms.md)[![GitHub Sponsors](https://img.shields.io/badge/--ea4aaa?logo=github&style=flat-square)](https://github.com/sponsors/llucax)[![Liberapay](https://img.shields.io/badge/--f6c915?logo=liberapay&logoColor=black&style=flat-square)](https://liberapay.com/llucax/donate)[![Paypal](https://img.shields.io/badge/--0070ba?logo=paypal&style=flat-square)](https://www.paypal.com/donate?hosted_button_id=UZRR3REUC4SY2)[![Buy Me A Coffee](https://img.shields.io/badge/--ff813f?logo=buy-me-a-coffee&logoColor=white&style=flat-square)](https://www.buymeacoffee.com/llucax)[![Patreon](https://img.shields.io/badge/--f96854?logo=patreon&logoColor=white&style=flat-square)](https://www.patreon.com/llucax)[![Flattr](https://img.shields.io/badge/--6bc76b?logo=flattr&logoColor=white&style=flat-square)](https://flattr.com/@llucax)
[![Sponsor (mateusfccp)](https://img.shields.io/badge/-Sponsor%20(mateusfccp)-555555?style=flat-square)](https://github.com/sponsors/mateusfccp)[![GitHub Sponsors](https://img.shields.io/badge/--ea4aaa?logo=github&style=flat-square)](https://github.com/sponsors/mateusfccp)

A [Dart](https://dart.dev/)
[timer](https://api.dart.dev/stable/dart-async/Timer/Timer.html) that can be
paused, resumed and reset.
A Dart timer that can be paused, resumed and reset.

## Example using `start()`, `pause()` and `reset()`
`PausableTimer` aims to be as similar and compatible as possible with Dart's
`Timer`, while providing extra funcionality.

```dart
import 'package:pausable_timer/pausable_timer.dart';
## How to use it

void main() async {
print('Create a timer that fires in 1 second, but it is not started yet');
final timer = PausableTimer(Duration(seconds: 1), () => print('Fired!'));
print('So we start it');
timer.start();
`PausableTimer` should work exactly the same as a regular `Timer`, but can be
paused, resumed and restarted with the respective methods (`.pause`, `.start`
and `.resume`).

print('And wait 1/2 second...');
await Future<void>.delayed(timer.duration ~/ 2);
print('Not yet fired, still 1/2 second to go!');
There are also additional getters to check if the timer is active, paused,
expired or cancelled.

print('We can pause it now');
timer.pause();
More detailed examples can be found in the
[example](https://github.com/mateusfccp/pausable_timer/tree/documentation_updates/example)
folder.

// When paused, time can pass but the timer won't be fired
print('And we wait a whole second...');
await Future<void>.delayed(timer.duration);
print("But our timer doesn't care while it's paused");
print('It will still wait for ${timer.duration - timer.elapsed} after '
"it's started again");
print('So we start it again');
timer.start();
print('And wait for 1/2 second again, it should have fired when we are done');
await Future<void>.delayed(timer.duration ~/ 2);
print('And we are done, "Fired!" should be up there 👆');
print('Now our timer completed ${timer.tick} tick');
print('We can reset it if we want to use it again');
timer.reset();
print('We have to start it again after the reset because it was not running');
timer.start();
print('Now we wait a whole second in one go...');
await Future<void>.delayed(timer.duration);
print('And we are done, so you should see "Fired!" up there again 👆');
print('Now the timer has ${timer.tick} ticks');
print('We can reset it and start it again');
timer.reset();
timer.start();
print('And you can cancel it too, so it will not fire again');
timer.cancel();
print("After a timer is cancelled, it can't be used again");
print('But important information can still be retrieved:');
print('duration: ${timer.duration}');
print('elapsed: ${timer.elapsed}');
print('tick: ${timer.tick}');
print('isPaused: ${timer.isPaused}');
print('isActive: ${timer.isActive}');
print('isExpired: ${timer.isExpired}');
print('isCancelled: ${timer.isCancelled}');
}
```

## Example pausable countdown implementation

```dart
// Example on how to implement countdown using PausableTimer.periodic
import 'dart:async';
import 'package:pausable_timer/pausable_timer.dart';
void main() async {
// We make it "late" to be able to use the timer in the timer's callback.
late final PausableTimer timer;
var countDown = 5;
print('Create a periodic timer that fires every 1 second and starts it');
timer = PausableTimer.periodic(
Duration(seconds: 1),
() {
countDown--;
if (countDown == 0) {
timer.pause();
}
print('\t$countDown');
},
)..start();
print('And wait 2.1 seconds...');
print('(0.1 extra to make sure there is no race between the timer and the '
'waiting here)');
await Future<void>.delayed(timer.duration * 2.1);
print('By now 2 events should have fired: 4, 3\n');
print('We can pause it now');
timer.pause();
print('And we wait for 2 more seconds...');
await Future<void>.delayed(timer.duration * 2);
print("But our timer doesn't care while it's paused\n");
print('So we start it again');
timer.start();
print('And wait for 3.1 seconds more...');
await Future<void>.delayed(timer.duration * 3.1);
print('And we are done: 2, 1 and 0 should have been printed');
print('The timer should be unpaused, inactive, expired and not cancelled');
print('isPaused: ${timer.isPaused}');
print('isActive: ${timer.isActive}');
print('isExpired: ${timer.isExpired}');
print('isCancelled: ${timer.isCancelled}');
print('We can now reset it and start it again, now for 3 seconds');
countDown = 3;
timer
..reset()
..start();
print('And wait for 3.1 seconds...');
await Future<void>.delayed(timer.duration * 3.1);
print('And it should be done printing: 2, 1 and 0');
}
```
1 change: 1 addition & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:pausable_timer/pausable_timer.dart';
void main() async {
print('Create a timer that fires in 1 second, but it is not started yet');
final timer = PausableTimer(Duration(seconds: 1), () => print('Fired!'));

print('So we start it');
timer.start();

Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
clock: ^1.1.0

dev_dependencies:
coverage: ^1.7.1
fake_async: ^1.3.1
lints: ^3.0.0
test: ^1.24.8
test: ">=1.24.0"

0 comments on commit af0ea71

Please sign in to comment.