Skip to content

Commit

Permalink
Merge pull request hyperledger-archives#439 from xuanyue202/master
Browse files Browse the repository at this point in the history
Fix async problem when resolving array relations
  • Loading branch information
fabric-composer-app authored Mar 13, 2017
2 parents de86a89 + 2f21c96 commit d142ef4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/composer-runtime/lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class Resolver {

// Go through each item in the array.
LOG.debug(method, 'Property value is an array, iterating over values', value.length);
return value.reduce((result, item, index) => {
return value.reduce((arrayReduceResult, item, index) => {

// Handle the array item.
if (item instanceof Resource) {

// Replace the property value with the resolved resource.
LOG.debug(method, 'Array item is a resource, resolving', item.toString());
return result.then(() => {
return arrayReduceResult.then(() => {
return this.resolveResource(item, resolveState);
}).then((newItem) => {
value[index] = newItem;
Expand All @@ -134,18 +134,18 @@ class Resolver {

// Replace the property value with the resolved relationship.
LOG.debug(method, 'Property value is a relationship, resolving', item.toString());
return result.then(() => {
return arrayReduceResult.then(() => {
return this.resolveRelationship(item, resolveState);
}).then((newItem) => {
value[index] = newItem;
});

} else {
LOG.debug(method, 'Array item is neither a resource or a relationship, ignoring', item);
return result;
return arrayReduceResult;
}

}, Promise.resolve());
}, result);

} else {
LOG.debug(method, 'Property value is neither a resource or a relationship, ignoring', value);
Expand Down

0 comments on commit d142ef4

Please sign in to comment.