-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watch features #6
Comments
Closing this since it is part of #24 |
Reopening since this will be done separately from #24, due to the internal API changes that will be needed. |
Noting my thoughts on how the watch features can be implemented, keeping in mind that the goal is to implement the various watch functions: File changes must be detected and an event dispatched to the listener passed to a watch function. One easy way to do this would be to have Perhaps: interface FileSystemEvent {
path: string;
// more can be added
}
abstract class FileSystem extends EventEmitter<Record<'change' | 'rename' | 'create' | 'delete', FileSystemEvent>> {
//...
}
// Then, an implementation can emit the event
class SomeFS extends FileSystem {
//...
async rename(path, /*...*/) {
this.emit('rename', { path });
//...
}
//...
}
// Finally, the watch functions can listen for these events
interface Watcher {
path: string
listener: WatchListener
}
const watchers: Set<Watcher>
function watch(path, listener) {
watchers.add({ path, listener })
}
// And they will be caught
function watchListener(eventType, event) {
for(const { path, listener } of watchers) {
if(event.path != path) { // or some other way to match it
continue;
}
listener({
eventType,
filename: path
});
}
}
function mount(point, fs) {
//...
fs.on('change', (event) => watchListener('change', event));
fs.on('rename', (event) => watchListener('change', event));
//...
} |
Originally jvilk/BrowserFS#163
By @amir-arad
The text was updated successfully, but these errors were encountered: