Autosave using a while loop?

I have a rich text editor and I want to autosave its content every 5 seconds or so.

I thought about setting up a while loop with 2 actions

  1. Fetch collection (save to DB)
  2. Time delay (5000ms)

and wrapping these in an ‘always true’ while loop.

I thought that the while loop would keep looping even if the fetch collection action fails (since true is always true).

However if the action fails, the loop stops.

How can I prevent this so that the workflow keeps on going no matter what?

Is there a specific reason why you would autosave every 5 seconds, instead of using a standard workflow of saving when changes are detected client side?

@thomlov The problem I have with this solution is that if the user is actively typing, the workflow gets restarted at every keystroke. In other words, the user’s input will only be saved if he stops typing/triggering the workflow & waits the debounce delay.

Let’s imagine the user’s wifi goes out in the middle of a long paragraph, none of it will be saved.

That’s why I was thinking a “do every Xms” workflow would be better suited :thinking:

It’s better to find a good debounce value, that saves when there is a natural break in the writing. Typically there will be som pause in the writing, that you will manage to save the text.

If you’re not afraid of your backend being overloaded just set a really low debounce value (100 ms)… I’m using 250ms.