shutdown 0.4.0

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

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 pub get

Alternatively, your editor might support pub get or flutter pub 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]
31
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on May 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16

Platforms

Detected platforms: Flutter, other

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

Health issues and suggestions

Document public APIs. (-1 points)

12 out of 12 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/shutdown_impl.dart. (-1 points)

Analysis of lib/src/shutdown_impl.dart reported 2 hints:

line 58 col 26: Use = to separate a named parameter from its default value.

line 59 col 26: Use = to separate a named parameter from its default value.

Dependencies

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