Refactor to use dispatch_io for tasks, and wait for EOF

Hopefully resolves #139, #135, #161.

/cc @joshaber @keithduncan
I don't think the latter will work because T Y P E S, and the former isn't really what I'm trying to express (this cast should never fail).