Skip to content

Instantly share code, notes, and snippets.

@johndstein
Created September 5, 2014 15:47
Show Gist options
  • Save johndstein/624bcdbb93626b00f880 to your computer and use it in GitHub Desktop.
Save johndstein/624bcdbb93626b00f880 to your computer and use it in GitHub Desktop.
Bluebird .settle() bug
var Promise = require('bluebird');
var winston = require('winston');
// returns big old file report json from mcube if found or null if
// not found.
function doMcube(md5) {
return Promise.resolve({
some: {
crazy: 'json'
}
});
}
// returns ??? from satori if found or null if
// not found.
function doSatori(md5) {
return new Promise(function(resolve) {
throw new Error('something bad happened');
});
}
// returns { isKnownBad: true | false }
function doNucleus(md5) {
return Promise.resolve({
isKnownBad: false
});
}
// So this guy takes an md5 and returns the following info from mcube, satori and
// baleen aka nucleus.
// {
// mcube: some big old stinking file report JSON,
// satori: ??
// nucleus: { isKnownBad: true | false }
// }
function enrich(md5) {
return Promise.settle([doMcube(md5), doSatori(md5), doNucleus(md5)])
.then(function(promiseInspections) {
var result = {
mcube: null,
satori: null,
nucleus: null
};
if (promiseInspections[0].isFulfilled()) {
result.mcube = promiseInspections[0].value();
} else {
winston.error('Error getting mcube info', promiseInspections[0].reason());
}
if (promiseInspections[1].isFulfilled()) {
result.satori = promiseInspections[1].value();
} else {
winston.error('Error getting satori info', promiseInspections[1].reason());
}
if (promiseInspections[2].isFulfilled()) {
result.nucleus = promiseInspections[2].value();
} else {
winston.error('Error getting nucleus info', promiseInspections[2].reason());
}
return result;
});
}
module.exports = {
enrich: enrich
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment