Shopify/batman — pull request #551 by hornairs (2012-09-11 22:31:28+00:00)
Title: Well defined promises

@nciagra @kristianpd please examine.

This makes promise accessors synchronously return the return value of the promise function. For example:

```coffeescript
@classAccessor 'totalCount', promise: (deliver) ->
@request 'count', (err, response) ->
deliver(err, response?.count)
0
```

now actually returns 0 until the request comes back. It didn't before. The trick is that if you forget to add a synchronous return value (which happens in the Shopify code base in a few places) then the synchronous return value of the `@request` call will be returned until the request comes back.

```coffeescript
@classAccessor 'totalCount', promise: (deliver) ->
@request 'count', (err, response) -> deliver(err, response?.count)
```

Up until recently, `@request` returned the result of `@_doStorageOperation` which returned the result of `StorageAdapter::perform` which returned some useless internal function by accident. Now, that returns undefined, so `@request` can safely be used in promise accessors without fear of weird return values.