kahnjw/endpoints — pull request #17 by kahnjw (2014-06-01 23:41:41+00:00)
Title: Make the request resonse cycle stateless

Assumptions about deferred objects were creeping into the code that could have lead to state changes. This makes the code look a little wonky, but it fixes those state problems.

Specifically there was an assumption that each endpoint only needed one Q.deferred object. Simply not true. An endpoint needs a Q.deferred object for every request made to the server. This is accomplished by wrapping Q.deferred creation into a closure which scopes the deferred into the callbacks of the promise. This keeps the MethodFactory objects stateless between requests, as the state is stored in a closure that called every time a new request is sent.