mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 09:15:29 +01:00
Return when queue is empty
This commit is contained in:
parent
70a55e9a2e
commit
3f0f97f762
|
@ -10,7 +10,7 @@ import debug from '../utils/debug.js';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class FileCacheProvider {
|
export default class FileCacheProvider {
|
||||||
private static readonly evictionQueue = new PQueue({concurrency: 1});
|
private readonly evictionQueue = new PQueue({concurrency: 1});
|
||||||
private readonly config: Config;
|
private readonly config: Config;
|
||||||
|
|
||||||
constructor(@inject(TYPES.Config) config: Config) {
|
constructor(@inject(TYPES.Config) config: Config) {
|
||||||
|
@ -70,7 +70,7 @@ export default class FileCacheProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.evictOldestIfNecessary();
|
await this.evictOldestIfNecessary();
|
||||||
});
|
});
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
@ -83,14 +83,16 @@ export default class FileCacheProvider {
|
||||||
*/
|
*/
|
||||||
async cleanup() {
|
async cleanup() {
|
||||||
await this.removeOrphans();
|
await this.removeOrphans();
|
||||||
this.evictOldestIfNecessary();
|
await this.evictOldestIfNecessary();
|
||||||
}
|
}
|
||||||
|
|
||||||
private evictOldestIfNecessary() {
|
private async evictOldestIfNecessary() {
|
||||||
if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) {
|
if (this.evictionQueue.size === 0 && this.evictionQueue.pending === 0) {
|
||||||
debug('Adding evictOldest task to queue');
|
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() {
|
private async evictOldest() {
|
||||||
|
@ -115,7 +117,7 @@ export default class FileCacheProvider {
|
||||||
|
|
||||||
// Continue to evict until we're under the limit
|
// Continue to evict until we're under the limit
|
||||||
debug('Scheduling another eviction');
|
debug('Scheduling another eviction');
|
||||||
void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this));
|
void this.evictionQueue.add(this.evictOldest.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('Finished evictOldest');
|
debug('Finished evictOldest');
|
||||||
|
|
Loading…
Reference in a new issue