Skip to content
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

Explore ignoring intermediate writes #2

Open
fabiospampinato opened this issue Jul 4, 2020 · 2 comments
Open

Explore ignoring intermediate writes #2

fabiospampinato opened this issue Jul 4, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@fabiospampinato
Copy link
Owner

If a write has been initiated, and another 10 writes to the same path have got queued up in the meantime, it's possible that the computer will crash before finishing all those writes, maybe it would be better to just skip intermediate writes and go straight to the last write queued up.

@aleksey-hoffman
Copy link

I agree, there's no point writing intermediate data. If the program requested to write some value 100 times in 1 second (which can happen when you use a slider to modify some setting quickly), there's no point writing all those changes, just write the last one. Though, it would probably be better to make this approach optional.

I think the current approach is also the cause of another problem. When I do exactly what I described above (modifying a value multiple times in a row quickly), I get the following error:

Uncaught (in promise) Error: Error: Error: Error: EPERM: operation not permitted, 
rename 'C:\app_path\settings.json.tmp-6623291918d97ceb' -> 'C:\app_path\settings.json'

I fixed it by wrapping this module's writeFile function with a custom throttle class instance that reduces the amount of calls to the function (calls once every 250 ms) and schedules the incoming values while waiting between the calls, but it doesn't create a queue, it just overwrites the existing values and then writes them when the 250ms waiting period is over.

Example:

// 1. Request a lot of consecutive writes
write({ key: 'imagePositionX', value: '12'})
write({ key: 'imagePositionX', value: '14'})
write({ key: 'imagePositionX', value: '15'})
write({ key: 'imagePositionY', value: '2'})

// 2. 
// - If throttle is waiting, schedule properties (overwrite with incoming values)
// - If throttle is running, write the properties from 'scheduledData'
const scheduledData = [
  { key: 'imagePositionX', value: '15'},
  { key: 'imagePositionY', value: '2'}
]

@fabiospampinato
Copy link
Owner Author

Triggering hundreds of writes to the same file in quick succession is kind of a separate problem at the app level, you probably shouldn't do that to being with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants