shutdown 0.4.2

Dart native
Flutter Android iOS

Prioritized events for graceful shutdown in server Dart applications.

shutdown #

Helps you release system or shared resources during unexpected application shutdown.

Usage #

A simple usage example:

import 'dart:async';

import 'package:shutdown/shutdown.dart' as shutdown;

Future main() async {
  shutdown.triggerOnSigInt();
  shutdown.triggerOnSigHup();

  final db = await _acquireDB();
  shutdown.addHandler(() async => db.close());

  // [do your stuff]

  // call it at the end, this is a successful exit
  await shutdown.shutdown();
}

Future _acquireDB() async => null; // TODO: implement

Tip #

Combine this library with package:stack_trace:

import 'package:shutdown/shutdown.dart' as shutdown;
import 'package:stack_trace/stack_trace.dart';

Future main() async {
  shutdown.triggerOnSigInt();
  shutdown.triggerOnSigHup();
  return Chain.capture(() async {
    // TODO: initialize, register shutdown handlers
    // do your stuff
    await shutdown.shutdown();
  }, onError: (error, Chain chain) async {
    // TODO: report/log error and stack
    await shutdown.shutdown(exitCode: -1);
  });
}
2
likes
90
pub points
60%
popularity

Publisher

agilord.com

Prioritized events for graceful shutdown in server Dart applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

More

Packages that depend on shutdown