Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart on exit event

Tags:

events

exit

dart

Is there a way to do something just before a Dart application running on the VM exits?

I'm writing a server application, so there is no specific point in time where my application will exit. I'm trying to talk to another process, but if a user closes my application (with ctr+c), or it crashes for some unknown reason, I would like to be able to tell that process to close as well.

It would be nice if something similar to this existed:

void main() {
  onExit().then(() {
    process.kill();
  });
}

Thanks.

Edit:

I figured out how to detect Ctr+C:

void main() {
  ProcessSignal.SIGINT.watch().listen((ProcessSignal signal) {
    print("exiting");
    exit(0);
  });
}

Now if the application is ran from the Dart editor, is there a way to detect that closing?

like image 626
Michael Peterson Avatar asked Jan 08 '14 02:01

Michael Peterson


1 Answers

Seems work in progress [POSIX signal handling (SIGINT, SIGTERM, SIGHUP, etc] (http://code.google.com/p/dart/issues/detail?id=15188)

like image 72
Günter Zöchbauer Avatar answered Oct 25 '22 03:10

Günter Zöchbauer