a2b556b937
Change-Id: Ia5c41dda6503e1fbb8cc6099835d07588425e2ba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128310 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
25 lines
680 B
Dart
25 lines
680 B
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library timer_cancel2_test;
|
|
|
|
import 'dart:async';
|
|
import 'package:expect/expect.dart';
|
|
|
|
main() {
|
|
// Test that a timeout handler can cancel itself.
|
|
var cancelTimer;
|
|
var completer = new Completer();
|
|
int calls = 0;
|
|
void cancelHandler(Timer timer) {
|
|
Expect.equals(1, ++calls);
|
|
cancelTimer.cancel();
|
|
completer.complete();
|
|
}
|
|
|
|
cancelTimer =
|
|
new Timer.periodic(const Duration(milliseconds: 1), cancelHandler);
|
|
return completer.future;
|
|
}
|