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

Handle exit signals gracefully and pipe stdio 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,
    outLog: exampleLogFile,
    errLog: exampleLogFile,
    onExit: onExit,
  );
}

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;
}
2
likes
0
pub points
52%
popularity

Publisher

verified publishertheoretically.online

Handle exit signals gracefully and pipe stdio to log files.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

path

More

Packages that depend on graceful