diff options
| author | Max Isom <[email protected]> | 2021-12-03 10:45:09 -0500 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2021-12-03 10:45:09 -0500 |
| commit | 3f0f97f762d0cf5c9be6dbc34b0bc081307058ef (patch) | |
| tree | 1ab617ed205d3b3ecd4838a0809bf97f4a3842b6 | |
| parent | 70a55e9a2e8df91d2e4dc0792a17d9b48f6f20d0 (diff) | |
| download | muse-3f0f97f762d0cf5c9be6dbc34b0bc081307058ef.tar.xz muse-3f0f97f762d0cf5c9be6dbc34b0bc081307058ef.zip | |
Return when queue is empty
| -rw-r--r-- | src/services/file-cache.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index b99c8c6..e82b705 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -10,7 +10,7 @@ import debug from '../utils/debug.js'; @injectable() export default class FileCacheProvider { - private static readonly evictionQueue = new PQueue({concurrency: 1}); + private readonly evictionQueue = new PQueue({concurrency: 1}); private readonly config: Config; constructor(@inject(TYPES.Config) config: Config) { @@ -70,7 +70,7 @@ export default class FileCacheProvider { } } - this.evictOldestIfNecessary(); + await this.evictOldestIfNecessary(); }); return stream; @@ -83,14 +83,16 @@ export default class FileCacheProvider { */ async cleanup() { await this.removeOrphans(); - this.evictOldestIfNecessary(); + await this.evictOldestIfNecessary(); } - private evictOldestIfNecessary() { - if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) { + private async evictOldestIfNecessary() { + if (this.evictionQueue.size === 0 && this.evictionQueue.pending === 0) { debug('Adding evictOldest task to queue'); - void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); + void this.evictionQueue.add(this.evictOldest.bind(this)); } + + return this.evictionQueue.onEmpty(); } private async evictOldest() { @@ -115,7 +117,7 @@ export default class FileCacheProvider { // Continue to evict until we're under the limit debug('Scheduling another eviction'); - void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); + void this.evictionQueue.add(this.evictOldest.bind(this)); } debug('Finished evictOldest'); |
