if (!this instanceof BuildCache)
throw Error('BuildCache is a constructor')
this.map = new Map()
+ this.diag = false
}
BuildCache.prototype.get = async function(key, build_func) {
let result = this.map.get(key)
if (result === undefined) {
+ if (this.diag)
+ console.log('building', key)
result = {deps: [key], time: Date.now()}
result.done = build_func(result)
this.map.set(key, result)
delete result.done
}
else if (result.done === undefined) {
+ if (this.diag)
+ console.log('checking', key)
result.done = (
async () => {
for (let i = 0; i < result.deps.length; ++i) {
stats = await fs_stat(result.deps[i])
if (stats.mtimeMs > result.time) {
+ if (this.diag)
+ console.log('rebuilding', key)
result.deps = [key]
result.time = Date.now()
await build_func(result)