shutdown 0.4.4 copy "shutdown: ^0.4.4" to clipboard
shutdown: ^0.4.4 copied to clipboard

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);
  });
}
8
likes
160
points
1.88k
downloads

Publisher

verified publisheragilord.com

Weekly Downloads

Prioritized events for graceful shutdown in server Dart applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on shutdown