Files
sdk/samples/embedder/timer.dart
T
Ivan Inozemtsev 51ea42537a Add support for flushing microtasks in dart_engine.h
Also add a sample for calling Dart functions which return/accept futures.

Change-Id: I932d0577709f4e068ccd3212797751ecb347c4f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408281
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-02-12 11:10:25 -08:00

38 lines
811 B
Dart

// Copyright (c) 2025, 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.
import 'dart:async';
void main() {
throw 'Unimplemented';
}
var _tickCount = 0;
Timer? _timer;
@pragma('vm:entry-point', 'call')
void startTimer(int millis) {
if (_timer == null) {
final period = Duration(milliseconds: millis);
_timer = Timer.periodic(period, (_) {
_tickCount++;
});
print('Started timer with period $period');
}
}
@pragma('vm:entry-point', 'call')
void stopTimer() {
_timer?.cancel();
_timer = null;
}
@pragma('vm:entry-point', 'call')
void resetTimer() {
_tickCount = 0;
}
@pragma('vm:entry-point', 'get')
int get ticks => _tickCount;