Ability to re-open closed documents in same connection

This patch makes it possible to close a document and open it at a later point using the same connection.

Instead of just passing a known document object to the callback it attempts the following depending on the state:

- if `open`, pass doc to callback
- if `opening`, add callback as event listener of `open` event
- if `closed`, attempt to re-open document calling callback with result

The patch also deletes documents from the connection when they emit a `closed` event to prevent memory leaks with large numbers of closed documents.

Fixes #167.