igrigorik/em-http-request — pull request #158 by lucasdicioccio (2011-12-07 16:01:06+00:00)
Title: slight API change on error at connection time

The example for fibers doesn't work if your DNS / routes are dead (i.e., on a TCP connection error of some reason):
The errback gets called immediately, hence you resume the fiber before resuming it.
I propose to call the close connection at next tick to maintain a consistent API.
Otherwise, users need to check the state of the connection before setting up callbacks/errbacks.

All specs pass, I've added one in a separate file because it requires 'fiber' which may not be available on 1.8.x

= commit text

this simplifies the API

A problem is that the error callback should fire before setting it up.
Hence, if we are in a fiber, and if we expected to yield after setting up
callbacks/errbacks. We would resume the fiber before yielding it,
generating a double resume error.
We work around this problem by calling :close/:on_error at next tick.
Hence, the errback's fiber will predictably be EM's reactor fiber.