create a detach helper and use detach helper in replace of process.nextTick
change detach to defer
Merge pull request #1168 from seanstrom/support/use-setimmediate-when-available

create a detach helper and use detach helper in replace of nextTick