Created
May 28, 2020 10:39
-
-
Save jonasfj/422d6ddf5006a258a1c96b9696949a82 to your computer and use it in GitHub Desktop.
Sample Dart program that handles `sigint`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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