Skip to content

Commit

Permalink
fix: make chaining off State:save correctly wait until file save
Browse files Browse the repository at this point in the history
  • Loading branch information
PriceHiller committed Nov 8, 2023
1 parent d5c7f8f commit 056191f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lua/orgmode/state/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ end
function State:save()
State._ctx.saved = false
--- We want to ensure the state was loaded before saving.
return self:load():finally(function()
utils
.writefile(cache_path, vim.json.encode(State.data))
:next(function()
State._ctx.saved = true
end)
:catch(function(err_msg)
vim.schedule_wrap(function()
utils.echo_warning('Failed to save current state! Error: ' .. err_msg)
end)
self:load()
return utils
.writefile(cache_path, vim.json.encode(State.data))
:next(function()
State._ctx.saved = true
end)
:catch(function(err_msg)
vim.schedule_wrap(function()
utils.echo_warning('Failed to save current state! Error: ' .. err_msg)
end)
end)
end)
end

---Load the state cache into the current state
Expand Down

0 comments on commit 056191f

Please sign in to comment.