Skip to content

Instantly share code, notes, and snippets.

@jurecuhalev
Last active January 14, 2017 20:40
Show Gist options
  • Save jurecuhalev/4bff9938ac543e3af6659054f1882b39 to your computer and use it in GitHub Desktop.
Save jurecuhalev/4bff9938ac543e3af6659054f1882b39 to your computer and use it in GitHub Desktop.
string = new Promise(function(resolve) {
// original code was just:
// resolve(ctx.processString(contents, relativePath));
//
// I want to emulate that and also invalidate cache in catch()
try {
resolve(ctx.processString(contents, relativePath));
} catch(e) {
return cache.remove(key).then(function(){
throw e;
});
}
}).then(function(result) {
if (typeof result === 'string') {
return { output: result };
} else {
return result;
}
}).then(function(value) {
var stringValue = JSON.stringify(value);
return cache.set(key, stringValue).then(function() {
return value;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment