Skip to content

Commit

Permalink
Rename EventEmitter to SequentialExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Mar 25, 2013
1 parent 6f63a7e commit 6e20551
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

var AWS = require('./core');
require('./event_listeners');
require('./event_emitter');
require('./sequential_executor');
require('./metadata_service');
var inherit = AWS.util.inherit;

Expand Down
8 changes: 4 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AWS.util.update(AWS, {

require('./config');
require('./http');
require('./event_emitter');
require('./sequential_executor');
require('./event_listeners');
require('./request');
require('./client');
Expand All @@ -57,8 +57,8 @@ require('./metadata_service');

/**
* @readonly
* @return [AWS.EventEmitter] a collection of global event listeners that are
* attached to every sent request.
* @return [AWS.SequentialExecutor] a collection of global event listeners that
* are attached to every sent request.
* @see AWS.Request AWS.Request for a list of events to listen for
* @example Logging the time taken to send a request
* AWS.events.on('send', function startSend(resp) {
Expand All @@ -70,4 +70,4 @@ require('./metadata_service');
*
* new AWS.S3.Client().listBuckets(); // prints 'Request took 0.285 seconds'
*/
AWS.events = new AWS.EventEmitter();
AWS.events = new AWS.SequentialExecutor();
14 changes: 7 additions & 7 deletions lib/event_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

var AWS = require('./core');
require('./event_emitter');
require('./sequential_executor');
require('./service_interface/json');
require('./service_interface/query');
require('./service_interface/rest');
Expand Down Expand Up @@ -83,7 +83,7 @@ AWS.EventListeners = {
};

AWS.EventListeners = {
Core: new AWS.EventEmitter().addNamedListeners(function(add, addAsync) {
Core: new AWS.SequentialExecutor().addNamedListeners(function(add, addAsync) {
addAsync('VALIDATE_CREDENTIALS', 'validate',
function VALIDATE_CREDENTIALS(req, doneCallback) {
req.client.config.getCredentials(function(err) {
Expand Down Expand Up @@ -262,35 +262,35 @@ AWS.EventListeners = {

}),

Json: new AWS.EventEmitter().addNamedListeners(function(add) {
Json: new AWS.SequentialExecutor().addNamedListeners(function(add) {
var svc = AWS.ServiceInterface.Json;
add('BUILD', 'build', svc.buildRequest);
add('EXTRACT_DATA', 'extractData', svc.extractData);
add('EXTRACT_ERROR', 'extractError', svc.extractError);
}),

Rest: new AWS.EventEmitter().addNamedListeners(function(add) {
Rest: new AWS.SequentialExecutor().addNamedListeners(function(add) {
var svc = AWS.ServiceInterface.Rest;
add('BUILD', 'build', svc.buildRequest);
add('EXTRACT_DATA', 'extractData', svc.extractData);
add('EXTRACT_ERROR', 'extractError', svc.extractError);
}),

RestJson: new AWS.EventEmitter().addNamedListeners(function(add) {
RestJson: new AWS.SequentialExecutor().addNamedListeners(function(add) {
var svc = AWS.ServiceInterface.RestJson;
add('BUILD', 'build', svc.buildRequest);
add('EXTRACT_DATA', 'extractData', svc.extractData);
add('EXTRACT_ERROR', 'extractError', svc.extractError);
}),

RestXml: new AWS.EventEmitter().addNamedListeners(function(add) {
RestXml: new AWS.SequentialExecutor().addNamedListeners(function(add) {
var svc = AWS.ServiceInterface.RestXml;
add('BUILD', 'build', svc.buildRequest);
add('EXTRACT_DATA', 'extractData', svc.extractData);
add('EXTRACT_ERROR', 'extractError', svc.extractError);
}),

Query: new AWS.EventEmitter().addNamedListeners(function(add) {
Query: new AWS.SequentialExecutor().addNamedListeners(function(add) {
var svc = AWS.ServiceInterface.Query;
add('BUILD', 'build', svc.buildRequest);
add('EXTRACT_DATA', 'extractData', svc.extractData);
Expand Down
4 changes: 2 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ AWS.Request = inherit({
this.params = params || {};
this.httpRequest = new AWS.HttpRequest(endpoint, region);

AWS.EventEmitter.call(this);
AWS.SequentialExecutor.call(this);
},

/**
Expand Down Expand Up @@ -397,7 +397,7 @@ AWS.Request = inherit({
}
});

AWS.util.mixin(AWS.Request, AWS.EventEmitter);
AWS.util.mixin(AWS.Request, AWS.SequentialExecutor);

/**
* This class encapsulates the the response information
Expand Down
20 changes: 10 additions & 10 deletions lib/event_emitter.js → lib/sequential_executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ var AWS = require('./core');
*
* @param eventName [String] the event name to register the listener for
* @param callback [Function] the listener callback function
* @return [AWS.EventEmitter] the same object for chaining
* @return [AWS.SequentialExecutor] the same object for chaining
*/
AWS.EventEmitter = AWS.util.inherit({
AWS.SequentialExecutor = AWS.util.inherit({

constructor: function EventEmitter() {
constructor: function SequentialExecutor() {
this._events = {};
},

Expand Down Expand Up @@ -132,12 +132,12 @@ AWS.EventEmitter = AWS.util.inherit({

/**
* Adds or copies a set of listeners from another list of
* listeners or EventEmitter object.
* listeners or SequentialExecutor object.
*
* @param listeners [map<String,Array<Function>>, EventEmitter]
* @param listeners [map<String,Array<Function>>, AWS.SequentialExecutor]
* a list of events and callbacks, or an event emitter object
* containing listeners to add to this emitter object.
* @return [AWS.EventEmitter] the emitter object, for chaining.
* @return [AWS.SequentialExecutor] the emitter object, for chaining.
* @example Adding listeners from a map of listeners
* emitter.addListeners({
* event1: [function() { ... }, function() { ... }],
Expand All @@ -146,18 +146,18 @@ AWS.EventEmitter = AWS.util.inherit({
* emitter.emit('event1'); // emitter has event1
* emitter.emit('event2'); // emitter has event2
* @example Adding listeners from another emitter object
* var emitter1 = new AWS.EventEmitter();
* var emitter1 = new AWS.SequentialExecutor();
* emitter1.on('event1', function() { ... });
* emitter1.on('event2', function() { ... });
* var emitter2 = new AWS.EventEmitter();
* var emitter2 = new AWS.SequentialExecutor();
* emitter2.addListeners(emitter1);
* emitter2.emit('event1'); // emitter2 has event1
* emitter2.emit('event2'); // emitter2 has event2
*/
addListeners: function addListeners(listeners) {
var self = this;

// extract listeners if parameter is an EventEmitter object
// extract listeners if parameter is an SequentialExecutor object
if (listeners._events) listeners = listeners._events;

AWS.util.each(listeners, function(event, callbacks) {
Expand Down Expand Up @@ -242,4 +242,4 @@ AWS.EventEmitter = AWS.util.inherit({
* {on} is the prefered method.
* @api private
*/
AWS.EventEmitter.prototype.addListener = AWS.EventEmitter.prototype.on;
AWS.SequentialExecutor.prototype.addListener = AWS.SequentialExecutor.prototype.on;
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

AWS = require('../lib/core')

describe 'AWS.EventEmitter', ->
beforeEach -> @emitter = new AWS.EventEmitter()
describe 'AWS.SequentialExecutor', ->
beforeEach -> @emitter = new AWS.SequentialExecutor()

describe 'addListeners', ->
it 'accepts a hash of events and functions', ->
Expand All @@ -35,9 +35,9 @@ describe 'AWS.EventEmitter', ->
@emitter.emit('otherEventName')
expect(triggers).toEqual([1, 1, 1])

it 'accepts an EventEmitter object', ->
it 'accepts a SequentialExecutor object', ->
triggers = [0, 0, 0]
listeners = new AWS.EventEmitter()
listeners = new AWS.SequentialExecutor()
listeners.on 'eventName', -> triggers[0] = 1
listeners.on 'eventName', -> triggers[1] = 1
listeners.on 'otherEventName', -> triggers[2] = 1
Expand Down

0 comments on commit 6e20551

Please sign in to comment.