elt547
What about allowing undo action by killing the process?
I really don’t like having “deleted” flags and such on database records. I thought about using elixir processes to schedule a deletion with :timer.sleep, and sending a kill message if the user clicks the undo button. Are there obvious drawbacks to implementing “undoable” actions this way?
# Schedule the deletion
pid = spawn(fn -> :timer.sleep(10_000); Posts.delete(post) end)
# User clicks the undo button
Process.exit(pid, :kill)
Most Liked
benwilson512
Not really no.
More to the point though, I’m not sure that the code here does what you want it to do. It won’t delete the records until 10 seconds in the future at all, which means if your user loads the page in another tab, the records will still show as not deleted.
A more traditional way to do this is to have a deleted_at column that you set immediately to NOW() when the user clicks delete. If you want to actually remove the rows at a future point you can clean it up later.







