I have to deal with long promise chains and subchains returned by function calls to semi-external libraries. I've run into a situation where I have to access value from a subchain from another subchain (simplified example below).
I'd like to achieve getting/querying a value that some previous promise has set without having to manually pass that value through every promise in the chain. This value doesn't have to be a return value, if that helps anything.
What would be the best practice for doing this? Note that since we're living in an async world, multiple instances of the same chain may be processing simultaneously...
function doNothing {
return true;
}
function setValue {
// somehow set <some> property to '1234'
}
function accessValue {
// somehow read from <some> property '1234'
}
Q( true ).then( doNothing )
.then( doNothing )
.then( doNothing )
.then( function() {
return Q( true ).then( doNothing ).then( setValue ).then( doNothing );
} )
.then( function() {
return Q( true ).then( doNothing ).then( accessValue ).then( doNothing );
} )
.done();