Fix race condition which results in spawn's errors

This commit is contained in:
streetturtle 2020-04-29 14:27:46 -04:00
parent da34ea0b35
commit 5a8113dfae

View file

@ -15,7 +15,6 @@ local naughty = require("naughty")
local gears = require("gears") local gears = require("gears")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local gfs = require("gears.filesystem") local gfs = require("gears.filesystem")
local gs = require("gears.string")
local HOME_DIR = os.getenv("HOME") local HOME_DIR = os.getenv("HOME")
@ -162,7 +161,6 @@ local function worker(args)
table.insert(rows, first_row) table.insert(rows, first_row)
for i, todo_item in ipairs(result.todo_items) do for i, todo_item in ipairs(result.todo_items) do
local checkbox = wibox.widget { local checkbox = wibox.widget {
@ -180,9 +178,10 @@ local function worker(args)
c:set_checked(not c.checked) c:set_checked(not c.checked)
todo_item.status = not todo_item.status todo_item.status = not todo_item.status
result.todo_items[i] = todo_item result.todo_items[i] = todo_item
spawn.easy_async_with_shell("echo '" .. json.encode(result) .. "' > " .. STORAGE) spawn.easy_async_with_shell("echo '" .. json.encode(result) .. "' > " .. STORAGE, function ()
todo_widget:update_counter(result.todo_items) todo_widget:update_counter(result.todo_items)
end) end)
end)
local trash_button = wibox.widget { local trash_button = wibox.widget {
{ {
@ -202,9 +201,10 @@ local function worker(args)
trash_button:connect_signal("button::press", function(c) trash_button:connect_signal("button::press", function(c)
table.remove(result.todo_items, i) table.remove(result.todo_items, i)
spawn.easy_async_with_shell("printf '" .. json.encode(result) .. "' > " .. STORAGE) spawn.easy_async_with_shell("printf '" .. json.encode(result) .. "' > " .. STORAGE, function ()
spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end) spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end)
end) end)
end)
local row = wibox.widget { local row = wibox.widget {
{ {