event_loop_watchdog 0.1.0 copy "event_loop_watchdog: ^0.1.0" to clipboard
event_loop_watchdog: ^0.1.0 copied to clipboard

A Dart package to help detect whenever your main `event loop` is blocked.

example/main.dart

/*
  This file is part of event_loop_watchdog.

  SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Sérgio Martins <sergio.martins@kdab.com>

  SPDX-License-Identifier: MIT
*/

/// A minimal example. fibonnacci() will block the event loop and a stack trace
/// will printed saying where it's hanging

import 'dart:async';
import 'package:event_loop_watchdog/event_loop_watchdog.dart';

int fibonacci(int n) {
  if (n == 1 || n == 2) return 1;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

void main() async {
  final wdog =
      WatchDog(allowedEventLoopStallDuration: Duration(milliseconds: 100));
  wdog.start();

  /// Run some expensive computation now and then:
  Timer.periodic(Duration(seconds: 1), (timer) {
    fibonacci(43);
  });
}
3
likes
140
points
5
downloads

Publisher

verified publisherkdab.com

Weekly Downloads

A Dart package to help detect whenever your main `event loop` is blocked.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

path, vm_service

More

Packages that depend on event_loop_watchdog