shutdown 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 72

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(() => 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);
  });
}

0.4.0

  • Enable Dart2 versions.
  • Handler-specific and overall timeouts for closing resources.

0.3.0

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)

0.2.0

  • Initial version: basic priorities.
  • OS signal hooks.

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  shutdown: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:shutdown/shutdown.dart';
  
Version Uploaded Documentation Archive
0.4.0 Aug 1, 2018 Go to the documentation of shutdown 0.4.0 Download shutdown 0.4.0 archive
0.3.0 Jun 27, 2018 Go to the documentation of shutdown 0.3.0 Download shutdown 0.3.0 archive
0.2.0 Jun 27, 2018 Go to the documentation of shutdown 0.2.0 Download shutdown 0.2.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, other

Primary library: package:shutdown/shutdown.dart with components: io, isolate.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <3.0.0