Refactor to use dispatch_io for tasks, and wait for EOF

Hopefully resolves #139, #135, #161.

/cc @joshaber @keithduncan
Can we use `DISPATCH_DATA_DESTRUCTOR_DEFAULT` for the destructor?