Skip to content

Instantly share code, notes, and snippets.

@jonasfj
Created May 28, 2020 10:39
Show Gist options
  • Save jonasfj/422d6ddf5006a258a1c96b9696949a82 to your computer and use it in GitHub Desktop.
Save jonasfj/422d6ddf5006a258a1c96b9696949a82 to your computer and use it in GitHub Desktop.
Sample Dart program that handles `sigint`.
// Copyright 2020 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import 'dart:async';
import 'dart:io';
Future<void> main() async {
var count = 0;
ProcessSignal.sigint.watch().forEach((s) {
count++;
print('child: Got a SIGINT $count times, hit it 3 times to terminate');
if (count >= 3) {
exit(0);
}
});
print('child: Sleep 5s');
await Future.delayed(Duration(seconds: 5));
print('child: 5 sec done.');
exit(55);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment