graceful 1.1.0 copy "graceful: ^1.1.0" to clipboard
graceful: ^1.1.0 copied to clipboard

outdated

Handle exit signals gracefully and pipe console output to log files.

example/graceful_example.dart

import 'package:graceful/graceful.dart';

// You can use a single file for both `out` and `err` messages.
const exampleLogFile = 'example/logs/out.log';

void main(List<String> args) {
  return bootstrap(
    run,
    args: args,
    onExit: onExit,
    fileOut: exampleLogFile,
    fileErr: exampleLogFile,
  );
}

void run(List<String> args) async {
  print('Program start');
  print('Waiting for 5 seconds...');
  await Future.delayed(Duration(seconds: 5));

  print('Done.');

  while (true) {
    await Future.delayed(Duration(seconds: 1));
    print('bump');
  }
}

Future<int> onExit() async {
  print('Cleaning up...');
  await Future.delayed(Duration(seconds: 1));
  print('Program exit');

  return 0; // Exit code
}
3
likes
90
pub points
41%
popularity

Publisher

verified publishertheoretically.online

Handle exit signals gracefully and pipe console output to log files.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

path

More

Packages that depend on graceful