This commit is contained in:
Morten Olsen
2023-03-28 08:10:46 +02:00
parent 9b1a067d56
commit 7adf03c83f
44 changed files with 1780 additions and 411 deletions

View File

@@ -1,16 +1,26 @@
import { readFile } from "fs/promises";
import { Observable } from "../../observable";
import { watch } from "fs";
import { readFile } from 'fs/promises';
import { Observable } from '../../observable';
import { watch } from 'fs';
type FileOptions = {
path: string;
};
const createFile = ({ path }: FileOptions) => {
const file = new Observable(async () => readFile(path, "utf-8"));
let watcher: ReturnType<typeof watch> | undefined;
const addWatcher = () => {
if (watcher) {
watcher.close();
}
watcher = watch(path, () => {
file.recreate();
addWatcher();
});
};
watch(path, () => {
file.recreate();
const file = new Observable(async () => {
addWatcher();
return readFile(path, 'utf-8');
});
return file;