fix watcher await

This commit is contained in:
Jonathan Jogenfors
2024-03-01 00:57:28 +01:00
parent e1872951e2
commit 298215a76a
4 changed files with 6 additions and 6 deletions

View File

@@ -46,7 +46,7 @@ export class LibraryService extends EventEmitter {
private configCore: SystemConfigCore;
private watchLibraries = false;
private watchLock = false;
private watchers: Record<string, () => void> = {};
private watchers: Record<string, () => Promise<void>> = {};
constructor(
@Inject(IAccessRepository) accessRepository: IAccessRepository,
@@ -175,7 +175,7 @@ export class LibraryService extends EventEmitter {
async unwatch(id: string) {
if (this.watchers[id]) {
this.watchers[id]();
await this.watchers[id]();
delete this.watchers[id];
}
}

View File

@@ -55,6 +55,6 @@ export interface IStorageRepository {
crawl(crawlOptions: CrawlOptionsDto): Promise<string[]>;
copyFile(source: string, target: string): Promise<void>;
rename(source: string, target: string): Promise<void>;
watch(paths: string[], options: WatchOptions, events: Partial<WatchEvents>): () => void;
watch(paths: string[], options: WatchOptions, events: Partial<WatchEvents>): () => Promise<void>;
utimes(filepath: string, atime: Date, mtime: Date): Promise<void>;
}

View File

@@ -148,6 +148,6 @@ export class FilesystemProvider implements IStorageRepository {
watcher.on(StorageEventType.UNLINK, (path) => events.onUnlink?.(path));
watcher.on(StorageEventType.ERROR, (error) => events.onError?.(error));
return () => watcher.close();
return async () => await watcher.close();
}
}

View File

@@ -11,7 +11,7 @@ interface MockWatcherOptions {
| StorageEventType.ERROR;
value: string;
}>;
close?: () => void;
close?: () => Promise<void>;
}
export const makeMockWatcher =
@@ -37,7 +37,7 @@ export const makeMockWatcher =
}
}
}
return () => close?.();
return async () => await close?.();
};
export const newStorageRepositoryMock = (reset = true): jest.Mocked<IStorageRepository> => {