Added notes from working with Nathan

This commit is contained in:
Mikayla Maki 2022-10-10 18:37:44 -07:00
parent cc8ae45012
commit 7ce758b343

View file

@ -114,6 +114,64 @@ impl ThemeSelector {
let theme_name = mat.string.clone();
// cx.global::<SettingsLock()>
// cx.global::<SettingsFile>() // lock
// 1) Truncation can cause data loss, make it atomic by creating tmp file and moving
// 2) Maybe firing too often? Conceptually want to commit
// Having a lock on the settings file
// -
// | |
// FS _
// General problem: whenever we want to persist stuff
// In memory representation -> File on disk
// Write font size,
// Write theme to disk
// Write -> See your own write -> Another Write
// Memory Write 1 -> Write To Disk 1, | Memory Write 2,
// Blocking ->>>>>> | Read From Disk 1,
// Discard | Read WHATEVER is from disk |
// Blocking lock ->
// Whenever we update the settings in memory, we enqueue a write to disk
// When we receive a file system event, we only honor it if all pending disk writes are complete.
// When the settings become dirty in memory, schedule a write to disk
// When we are sure the write is completed, consider the settings clean
// Only read settings from disk into memory when in memory settings are clean
// read settings just does not happen, if the settings are dirty
// 10 settings queued up:
// lock() -> Only needs to be on the file
// How to set a setting:
// write to memory
// Read the whole file from disk
// Surgically inject the setting string
// Write to disk
// unlock()
// Write 10 x change font size
// Read-open-write font size
// Read-open-write font size
// Read-open-write font size
// Read-open-write font size
// Read-open-write font size
// ..
// Read from file system, only gets the latest font size and uselessly sets font size
// `SettingsFile`
// You can non-blocking, write to it as much as you need
// Debounces your changes, waits for you to be done, and then flushes them all to the file system
// And blocks the read
// Read and write to memory. ^ up from the file system
// If there's pendings writes, we need to wait until this whole thing is done'
cx.background()
.spawn(async move {
match write_theme_name(theme_name).await {