Skip to content

Instantly share code, notes, and snippets.

@raine
Created September 8, 2015 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raine/133a885c9fbd523ea1b3 to your computer and use it in GitHub Desktop.
Save raine/133a885c9fbd523ea1b3 to your computer and use it in GitHub Desktop.
const cachedReadFile = (function() {
const cache = new Map();
return (p) => {
if (cache.has(p)) return Promise.resolve(cache.get(p));
else return readFile(p).tap((file) => cache.set(p, file));
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment