d3904f5a54
Change-Id: I6ccbe1494165c2bda142ece13584c4738e3b43e6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425347 Commit-Queue: Lasse Nielsen <lrn@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
27 lines
687 B
Dart
27 lines
687 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;
|
|
}
|