Refactor to use dispatch_io for tasks, and wait for EOF

Hopefully resolves #139, #135, #161.

/cc @joshaber @keithduncan
> I don't think there should be a one-to-one mapping between types and files

I tend to favour this approach across all languages, I find it makes finding things easier, but you’re right that there’s no technical reason for or against