Prefer setImmediate to process.nextTick.

This avoids errors due to recursive process.nextTick calls. (Supersedes #194.)