Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top