Unitech/pm2-interface — pull request #2 by bretcope (2013-11-20 19:30:38+00:00)
Title: Add disconnect method

I was writing some test scripts with pm2-interface and found it frustrating that the scripts had to be terminated manually. I wanted a way to indicate I was done interacting with PM2, and allow my script to terminate automatically whenever the event loop became empty.

So I added a disconnect method which simply closes the two internally opened sockets.

```javascript
this.disconnect = function () {
self.sub_sock.close();
self.rpc_sock.close();
};
```

Usage:

```javascript
ipm2.on('ready', function() {

// ...

ipm2.disconnect();
});
```

This could have be done already outside this module by making those calls externally:

```javascript
ipm2.on('ready', function() {

// ...

ipm2.sub_sock.close();
ipm2.rpc_sock.close();
});
```

But this was non-obvious, seems like bad practice, and a easy way to break compatibility in the future.

I called it `disconnect` instead of `close` so that there would be less confusion about whether you're closing a connection to PM2, closing PM2 itself, or closing processes that PM2 is monitoring.

README is updated to reflect this addition.

I think this will help others. Let me know if you have any differing opinions.