Skip to content
8 changes: 4 additions & 4 deletions lib/AbstractReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class AbstractReader {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {boolean} [options.nodir=true] Do not match directories
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
byPath(virPath, options = {nodir: true}) {
const trace = new Trace(virPath);
return this._byPath(virPath, options, trace).then(function(result) {
return this._byPath(virPath, options, trace).then(function(resource) {
trace.printReport();
return result;
return resource;
});
}

Expand Down Expand Up @@ -99,7 +99,7 @@ class AbstractReader {
* @protected
* @param {string} virPath Virtual path
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, trace) {
throw new Error("Not implemented");
Expand Down
2 changes: 1 addition & 1 deletion lib/DuplexCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DuplexCollection extends AbstractReaderWriter {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
return this._combo._byPath(virPath, options, trace);
Expand Down
10 changes: 5 additions & 5 deletions lib/ReaderCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ReaderCollection extends AbstractReader {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
const that = this;
Expand All @@ -60,13 +60,13 @@ class ReaderCollection extends AbstractReader {
Deliver files that can be found fast at the cost of slower response times for files that cannot be found.
*/
return Promise.race(this._readers.map(function(resourceLocator) {
return resourceLocator._byPath(virPath, options, trace).then(function(result) {
return resourceLocator._byPath(virPath, options, trace).then(function(resource) {
return new Promise(function(resolve, reject) {
trace.collection(that._name);
resolveCount++;
if (result) {
result.pushCollection(that._name);
resolve(result);
if (resource) {
resource.pushCollection(that._name);
resolve(resource);
} else if (resolveCount === resourceLocatorCount) {
resolve(null);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/ReaderCollectionPrioritized.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ class ReaderCollectionPrioritized extends AbstractReader {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
const that = this;
const byPath = (i) => {
if (i > this._readers.length - 1) {
return null;
}
return this._readers[i]._byPath(virPath, options, trace).then((result) => {
if (result) {
result.pushCollection(this._name);
return result;
return this._readers[i]._byPath(virPath, options, trace).then((resource) => {
if (resource) {
resource.pushCollection(that._name);
return resource;
} else {
return byPath(++i);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Resource {
* @param {Object} parameters Parameters
* @param {string} parameters.path Virtual path
* @param {Object} [parameters.statInfo] File stat information
* @param {Buffer} [parameters.buffer] Content of this resources as a Buffer instance
* @param {Buffer} [parameters.s] Content of this resources as a Buffer instance
* (cannot be used in conjunction with parameters string, stream or createStream)
* @param {string} [parameters.string] Content of this resources as a string
* (cannot be used in conjunction with parameters buffer, stream or createStream)
Expand Down
3 changes: 2 additions & 1 deletion lib/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AbstractAdapter extends AbstractReaderWriter {
*
* @abstract
* @private
* @param {string|Array} virPattern GLOB pattern as string or an array of glob patterns for virtual directory structure
* @param {string|Array} virPattern GLOB pattern as string or an array of
* glob patterns for virtual directory structure
* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FileSystem extends AbstractAdapter {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Memory extends AbstractAdapter {
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
return new Promise((resolve, reject) => {
Expand Down
27 changes: 15 additions & 12 deletions lib/tracing/traceSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@ function someTraceStarted() {
}

function someTraceEnded() {
tracesRunning--;
if (tracesRunning > 0) {
return;
}
return new Promise(function(resolve, reject) {
tracesRunning--;
if (tracesRunning > 0) {
resolve();
}

if (timeoutId) {
clearTimeout(timeoutId);
}
traceData.timeDiff = process.hrtime(traceData.startTime);
timeoutId = setTimeout(function() {
report();
reset();
}, 2000);
if (timeoutId) {
clearTimeout(timeoutId);
}
traceData.timeDiff = process.hrtime(traceData.startTime);
timeoutId = setTimeout(function() {
report();
reset();
resolve();
}, 2000);
});
}

function pathCall() {
Expand Down
Loading