Better names.

This commit is contained in:
André Cruz
2013-04-10 20:45:47 +01:00
parent 1c7e272ac3
commit 3116fde51c
3 changed files with 27 additions and 27 deletions

View File

@@ -166,7 +166,7 @@ The unit of work is a central entity in which state will be stored during the un
- Guarantees that a maximum of X packages are being resolved at every instant.
- Guarantees that packages with the same endpoint will not be resolved at the same time.
- Guarantees that packages with the exact same endpoint and range will not be resolved twice.
- Stores all the resolved/unresolved packages during the unroll of the dependency tree.
- Stores all the resolved/failed packages during the unroll of the dependency tree.
- When a package fails to resolve, it will make all the other enqueued ones to fail-fast.
------------
@@ -177,7 +177,7 @@ The unit of work is a central entity in which state will be stored during the un
- dequeue - fired when a package is dequeued
- before_resolve - fired when a package is about to be resolved (fired after dequeue)
- resolve - fired when a package resolved successfully
- unresolve - fired when a package failed to resolve
- failed - fired when a package failed to resolve
With this events, it will be possible to track the current status of each package during the expansion of the dependency tree.
@@ -198,7 +198,7 @@ The promise is fulfilled when the package is accepted to be resolved or is rejec
When fullfilled, a `done` function is passed that should be called when the resolve process of the package is finished:
Throws an error if the package is already queued or being resolved.
- If the package failed resolving, it should be called with an instance of `Error`. In that case, the package will be marked as unresolved and all the remaining enqueued packages will have the `enqueue` promise rejected, making the whole process to fail-fast.
- If the package failed resolving, it should be called with an instance of `Error`. In that case, the package will be marked as failed and all the remaining enqueued packages will have the `enqueue` promise rejected, making the whole process to fail-fast.
- If the packages succeed resolving, it should be called with no arguments. In that case, the package will be marked as resolved
#### UnitOfWork#dequeue(package) -> Itself
@@ -208,9 +208,9 @@ Removes a previously enqueued package.
Returns an array of resolved packages whose names are `name`.
When called without a name, returns an object with all the resolved packages.
#### UnitOfWork#getUnresolved(name) -> Itself
Returns an array of unresolved packages whose names are `name`.
When called without a name, returns an object with all the unresolved packages.
#### UnitOfWork#getFailed(name) -> Itself
Returns an array of packages that failed to resulve whose names are `name`.
When called without a name, returns an object with all the failed packages.
### Project / Manager -> EventEmitter

View File

@@ -20,7 +20,7 @@ var UnitOfWork = function (options) {
this._beingResolved = [];
this._beingResolvedEndpoints = {};
this._resolved = {};
this._unresolved = {};
this._failed = {};
this._completed = {};
};
@@ -80,8 +80,8 @@ UnitOfWork.prototype.getResolved = function (name) {
return name ? this._resolved[name] || [] : this._resolved;
};
UnitOfWork.prototype.getUnresolved = function (name) {
return name ? this._unresolved[name] || [] : this._unresolved;
UnitOfWork.prototype.getFailed = function (name) {
return name ? this._failed[name] || [] : this._failed;
};
// -----------------
@@ -181,11 +181,11 @@ UnitOfWork.prototype._onPackageDone = function (pkg, err) {
arr = this._resolved[pkgName] = this._resolved[pkgName] || [];
arr.push(pkg);
this.emit('resolve', pkg);
// Otherwise, it failed to resolve so we mark it as unresolved
// Otherwise, it failed to resolve so we mark it as failed
} else {
arr = this._unresolved[pkgName] = this._unresolved[pkgName] || [];
arr = this._failed[pkgName] = this._failed[pkgName] || [];
arr.push(pkg);
this.emit('unresolve', pkg);
this.emit('failed', pkg);
// If fail fast is enabled, make every other package in the queue to fail
this._failAll = this._options.failFast;

View File

@@ -187,15 +187,15 @@ describe('UnitOfWork', function () {
});
});
describe('.getUnresolved()', function () {
describe('.getFailed()', function () {
it('should always return a valid array/object', function () {
var unitOfWork = new UnitOfWork();
expect(unitOfWork.getUnresolved('foo')).to.eql([]);
expect(unitOfWork.getUnresolved()).to.eql({});
expect(unitOfWork.getFailed('foo')).to.eql([]);
expect(unitOfWork.getFailed()).to.eql({});
});
it('should return unresolved packages of a specific name', function (done) {
it('should return failed packages of a specific name', function (done) {
var unitOfWork = new UnitOfWork({ failFast: false }),
pkg1 = new Package('foo', { name: 'foo' }),
pkg2 = new Package('bar', { name: 'bar' }),
@@ -215,11 +215,11 @@ describe('UnitOfWork', function () {
unitOfWork.enqueue(pkg4).then(error(100));
setTimeout(function () {
arr = unitOfWork.getUnresolved('foo');
arr = unitOfWork.getFailed('foo');
expect(arr.length).to.be(2);
expect(arr[0]).to.equal(pkg1);
expect(arr[1]).to.equal(pkg3);
arr = unitOfWork.getUnresolved('bar');
arr = unitOfWork.getFailed('bar');
expect(arr.length).to.be(2);
expect(arr[0]).to.equal(pkg2);
expect(arr[1]).to.equal(pkg4);
@@ -228,7 +228,7 @@ describe('UnitOfWork', function () {
}, 500);
});
it('should return all unresolved packages', function (done) {
it('should return all failed packages', function (done) {
var unitOfWork = new UnitOfWork({ failFast: false }),
pkg1 = new Package('foo', { name: 'foo' }),
pkg2 = new Package('bar', { name: 'bar' }),
@@ -248,10 +248,10 @@ describe('UnitOfWork', function () {
unitOfWork.enqueue(pkg4).then(error(100));
setTimeout(function () {
obj = unitOfWork.getUnresolved();
obj = unitOfWork.getFailed();
expect(Object.keys(obj)).to.eql(['foo', 'bar']);
expect(obj.foo).to.equal(unitOfWork.getUnresolved('foo'));
expect(obj.bar).to.equal(unitOfWork.getUnresolved('bar'));
expect(obj.foo).to.equal(unitOfWork.getFailed('foo'));
expect(obj.bar).to.equal(unitOfWork.getFailed('bar'));
done();
}, 500);
@@ -259,7 +259,7 @@ describe('UnitOfWork', function () {
});
describe('general stuff', function () {
it('should let only "maxConcurrent" packages to resolve at the same time', function (done) {
it('should let only allow "maxConcurrent" packages to resolve at the same time', function (done) {
var unitOfWork = new UnitOfWork({ maxConcurrent: 2 }),
nrBeingResolved = 0,
pkg1 = new Package('foo'),
@@ -350,7 +350,7 @@ describe('UnitOfWork', function () {
});
});
it('should fire "dequeue", "before_resolve", "resolve" and "unresolve" during the resolve process', function (done) {
it('should fire "dequeue", "before_resolve", "resolve" and "failed" during the resolve process', function (done) {
var unitOfWork = new UnitOfWork(),
events = [],
pkg1 = new Package('foo'),
@@ -365,8 +365,8 @@ describe('UnitOfWork', function () {
unitOfWork.on('resolve', function (pkg) {
events.push('resolve', pkg.getEndpoint());
});
unitOfWork.on('unresolve', function (pkg) {
events.push('unresolve', pkg.getEndpoint());
unitOfWork.on('failed', function (pkg) {
events.push('failed', pkg.getEndpoint());
});
unitOfWork.enqueue(pkg1).then(function (cb) {
@@ -383,7 +383,7 @@ describe('UnitOfWork', function () {
'dequeue', pkg2.getEndpoint(),
'before_resolve', pkg2.getEndpoint(),
'resolve', pkg1.getEndpoint(),
'unresolve', pkg2.getEndpoint()
'failed', pkg2.getEndpoint()
]);
done();
}, 500);