use next-tick instead of setImmediate
use `write` and `error` in core.js