This mirrors the implementation in the old 0.15 release, but is quite a bit simpler now that we're built on the nonblocking API!