Prioritized events for graceful shutdown in server Dart applications.
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(() => db.close());
// [do you stuff]
// call it at the end, this is a successful exit
await shutdown.shutdown();
}
Future _acquireDB() async => null; // TODO: implement
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);
});
}
Breaking changes
The suggested way is to use shutdown
prefix when using the package, methods were renamed accordingly:
addShutdownHandler
-> addHandler
registerDefaultProcessSignals
-> triggerOnSigInt
(and similar ones)example/shutdown.dart
import 'dart:async';
import 'package:shutdown/shutdown.dart' as shutdown;
Future main() async {
shutdown.triggerOnSigInt();
shutdown.triggerOnSigHup();
final db = await _acquireDB();
shutdown.addHandler(() => db.close());
// [do you stuff]
// call it at the end, this is a successful exit
await shutdown.shutdown();
}
Future _acquireDB() async => null; // TODO: implement
Add this to your package's pubspec.yaml file:
dependencies:
shutdown: ^0.3.0
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:shutdown/shutdown.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.4.0 | Aug 1, 2018 |
|
|
0.3.0 | Jun 27, 2018 |
|
|
0.2.0 | Jun 27, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
15
|
Health:
Code health derived from static analysis.
[more]
|
--
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
--
|
Overall:
Weighted score of the above.
[more]
|
8
|
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Support Dart 2 in pubspec.yaml
.
The SDK constraint in pubspec.yaml
doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.
Make sure dartdoc
successfully runs on your package's source files. (-10 points)
Dependencies were not resolved.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.55.0 <2.0.0 |