Emit "drain" notification

When the queue is empty and all notifications have been transmitted to Apple emit an event.

Also tidied up some of the shutdown handling code as this shares some logic with the above.

Fixes #199