Skip to content

Refactor internals to use event based callbacks #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jan 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9badd24
Initial events
lsegal Dec 20, 2012
0e2b366
Rename promise.js to request.js
lsegal Dec 25, 2012
a407c8e
Add AWS.EventEmitter class
lsegal Dec 25, 2012
85b378b
Initial refactor of event-based request system
lsegal Dec 27, 2012
f269f4b
Fix jshint warnings and relax sub checking
lsegal Dec 27, 2012
02cfd40
AWS.util.copy should not copy null/undefined
lsegal Dec 27, 2012
14c79ac
Fix integration helper function
lsegal Dec 27, 2012
7ccebc2
Fix mapping of Action parameter in Query service interface
lsegal Dec 28, 2012
d557f57
AWS.util.inherit should create pass-through ctor if constructor not s…
lsegal Dec 28, 2012
69e11b3
Move service client tests to service interface test directory
lsegal Dec 28, 2012
c1fe88f
Convert service interface tests to new module format
lsegal Dec 28, 2012
6fd9cad
Ensure request always has params
lsegal Dec 28, 2012
70c7bdc
Rest interface should assign response.data
lsegal Dec 28, 2012
ddb31fa
Fix typo in Rest header population
lsegal Dec 28, 2012
f3dc590
Don't assign empty request bodies (breaks tests)
lsegal Dec 28, 2012
520261f
Rewrite RequestHandler tests as EventListener tests
lsegal Dec 28, 2012
e25b487
Add check for NetworkingError in Client.retryableError()
lsegal Dec 28, 2012
6227be1
Move FINALIZE_ERROR listener with other retry events
lsegal Dec 28, 2012
f6a5862
Fix off-by-1 error in RETRY_DELAY_SEND event
lsegal Dec 28, 2012
3aaf7fe
Fix typo in httpError emitter
lsegal Dec 28, 2012
990b659
Clear response between calls to Request.send()
lsegal Dec 28, 2012
a59e3cd
Don't set retryable on errors, let event logic handle that
lsegal Dec 28, 2012
5316258
Re-add streaming support by auto-removing HTTP_DATA event
lsegal Dec 28, 2012
7969f37
Update attributions
lsegal Jan 2, 2013
c38a4fa
Response HTTP body should be initialized to empty string
lsegal Jan 2, 2013
d1cba83
307 error should always be retryable
lsegal Jan 2, 2013
284d8e7
Remove response property from AWSRequest
lsegal Jan 3, 2013
9d272ea
Move AWSResponse.httpRequest into AWSRequest
lsegal Jan 3, 2013
f71b0d0
buildRequest now accepts `request` parameter.
lsegal Jan 3, 2013
0ed25a0
Rename AWSRequest/AWSResponse to Request/Response
lsegal Jan 3, 2013
c4d8512
Properly load canned set of credentials for unit tests
lsegal Jan 3, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"maxparams": false,
"maxdepth": false,
"maxstatements": 40,
"maxcomplexity": 5
"maxcomplexity": 5,
"sub": true
}
52 changes: 26 additions & 26 deletions doc-src/dynamodb.docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ AWS.DynamoDB = inherit({})
* * +ConsistentRead+ - (<tt>Boolean</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -156,7 +156,7 @@ AWS.DynamoDB = inherit({})
* binary attributes.
* * +AttributesToGet+ - (<tt>Array<String></tt>)
* * +ConsistentRead+ - (<tt>Boolean</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method batchWriteItem(params, callback)
Expand Down Expand Up @@ -228,7 +228,7 @@ AWS.DynamoDB = inherit({})
* binary attributes.
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -302,7 +302,7 @@ AWS.DynamoDB = inherit({})
* * +NS+ - (<tt>Array<String></tt>) A set of numbers.
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of
* binary attributes.
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method createTable(params, callback)
Expand Down Expand Up @@ -343,7 +343,7 @@ AWS.DynamoDB = inherit({})
* WriteCapacityUnits.
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -383,7 +383,7 @@ AWS.DynamoDB = inherit({})
* * +WriteCapacityUnits+ - (<tt>Integer</tt>)
* * +TableSizeBytes+ - (<tt>Integer</tt>)
* * +ItemCount+ - (<tt>Integer</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method deleteItem(params, callback)
Expand Down Expand Up @@ -450,7 +450,7 @@ AWS.DynamoDB = inherit({})
* * +ReturnValues+ - (<tt>String</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand All @@ -475,7 +475,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method deleteTable(params, callback)
Expand All @@ -486,7 +486,7 @@ AWS.DynamoDB = inherit({})
* _ (underscore), - (hyphen) and . (period).
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -526,7 +526,7 @@ AWS.DynamoDB = inherit({})
* * +WriteCapacityUnits+ - (<tt>Integer</tt>)
* * +TableSizeBytes+ - (<tt>Integer</tt>)
* * +ItemCount+ - (<tt>Integer</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method describeTable(params, callback)
Expand All @@ -538,7 +538,7 @@ AWS.DynamoDB = inherit({})
* 0-9, _ (underscore), - (hyphen) and . (period).
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -578,7 +578,7 @@ AWS.DynamoDB = inherit({})
* * +WriteCapacityUnits+ - (<tt>Integer</tt>)
* * +TableSizeBytes+ - (<tt>Integer</tt>)
* * +ItemCount+ - (<tt>Integer</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method getItem(params, callback)
Expand Down Expand Up @@ -628,7 +628,7 @@ AWS.DynamoDB = inherit({})
* * +ConsistentRead+ - (<tt>Boolean</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand All @@ -651,7 +651,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method listTables(params, callback)
Expand All @@ -665,7 +665,7 @@ AWS.DynamoDB = inherit({})
* * +Limit+ - (<tt>Integer</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand All @@ -678,7 +678,7 @@ AWS.DynamoDB = inherit({})
* ExclusiveStartTableName in a new request to continue the list
* until all the table names are returned. If this value is null,
* all table names have been returned.
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method putItem(params, callback)
Expand Down Expand Up @@ -724,7 +724,7 @@ AWS.DynamoDB = inherit({})
* * +ReturnValues+ - (<tt>String</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand All @@ -748,7 +748,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method query(params, callback)
Expand Down Expand Up @@ -853,7 +853,7 @@ AWS.DynamoDB = inherit({})
* attributes.
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -904,7 +904,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method scan(params, callback)
Expand Down Expand Up @@ -989,7 +989,7 @@ AWS.DynamoDB = inherit({})
* attributes.
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -1043,7 +1043,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method updateItem(params, callback)
Expand Down Expand Up @@ -1126,7 +1126,7 @@ AWS.DynamoDB = inherit({})
* * +ReturnValues+ - (<tt>String</tt>)
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand All @@ -1150,7 +1150,7 @@ AWS.DynamoDB = inherit({})
* * +BS+ - (<tt>Array<Base64 Encoded Data></tt>) A set of binary
* attributes.
* * +ConsumedCapacityUnits+ - (<tt>Float</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
* @!method updateTable(params, callback)
Expand All @@ -1171,7 +1171,7 @@ AWS.DynamoDB = inherit({})
* WriteCapacityUnits.
* @callback callback function(err, data)
* Called when a response from the service is returned. If a
* callback is not supplied, you must call {AWS.AWSRequest.send}
* callback is not supplied, you must call {AWS.Request.send}
* on the returned request object to initiate the request.
* @param err [Object] the error object returned from the request.
* Set to +null+ if the request is successful.
Expand Down Expand Up @@ -1211,7 +1211,7 @@ AWS.DynamoDB = inherit({})
* * +WriteCapacityUnits+ - (<tt>Integer</tt>)
* * +TableSizeBytes+ - (<tt>Integer</tt>)
* * +ItemCount+ - (<tt>Integer</tt>)
* @return [AWS.AWSRequest] a handle to the operation request for
* @return [AWS.Request] a handle to the operation request for
* subsequent event callback registration.
*
*
Expand Down
22 changes: 11 additions & 11 deletions doc-src/guide/MakingRequests.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ The `error` and `data` parameters are described in the "Response Object"
section below.

Note that if you do not specify a callback, the operation will
return an `AWS.AWSRequest` object that must be manually sent using
return an `AWS.Request` object that must be manually sent using
the `send()` method:

```js
// create the AWS.AWSRequest object
// create the AWS.Request object
var request = new AWS.EC2().client.describeInstances();

// register a callback to report on the data
Expand All @@ -43,10 +43,10 @@ request.done(function(resp) {
request.send();
```

### The Response Object (`AWS.AWSResponse`)
### The Response Object (`AWS.Response`)

The response object is passed into each callback function so
that you can access response data. The `AWS.AWSResponse` object that
that you can access response data. The `AWS.Response` object that
is passed in contains two important properties to get at this data:

When using the standard callback mechanism, the two properties will
Expand Down Expand Up @@ -88,7 +88,7 @@ before attempting to access the `response.data` property.

Currently, you can register callbacks for various events by
either using the simplified callback syntax, or by using the callback
methods on the returned `AWS.AWSRequest` object.
methods on the returned `AWS.Request` object.

#### Simplified Callback Method

Expand All @@ -101,9 +101,9 @@ For example:
```js
s3.client.listBuckets(function(error, data) {
if (err) {
console.log(error); // error is AWSResponse.error
console.log(error); // error is Response.error
} else {
console.log(data); // data is AWSResponse.data
console.log(data); // data is Response.data
}
});
```
Expand All @@ -119,7 +119,7 @@ Prints (assuming the request succeeded):
```

The error and data parameters accepted are equivalent to the `error` and
`data` properties discussed in the `AWS.AWSResponse` response object section
`data` properties discussed in the `AWS.Response` response object section
above.

If you are passing parameters to the operation, the callback should be placed
Expand All @@ -131,10 +131,10 @@ s3.client.getObject({Bucket: 'bucket', Key: 'key'}, function(err, data) {
});
```

#### AWS.AWSRequest Callbacks
#### AWS.Request Callbacks

You can alternatively register callbacks on events provided by the
`AWS.AWSRequest` object returned by each low-level client operation method.
`AWS.Request` object returned by each low-level client operation method.
This request object exposes the `done`, `fail`, `data`, and `always`
events, each taking a callback that accepts the response object.

Expand Down Expand Up @@ -221,7 +221,7 @@ request.always(function(response) {
## Binding Custom Context Data on a Callback

By default, the `this` context of a callback function registered on an
event will be the `AWS.AWSResponse` object returned from the service.
event will be the `AWS.Response` object returned from the service.
In some cases, it may be necessary to pass extra custom context to these
functions; in these cases, you can bind a custom value to be used as the
`this` context object when the callbacks are executed. To do so, pass
Expand Down
Loading