diff --git a/lua/pending/sync/gtasks.lua b/lua/pending/sync/gtasks.lua index a2a6da0..8b918c2 100644 --- a/lua/pending/sync/gtasks.lua +++ b/lua/pending/sync/gtasks.lua @@ -436,15 +436,27 @@ local function sync_setup(access_token) return tasklists, s, now_ts end +local _in_flight = false + ---@param callback fun(access_token: string): nil local function with_token(callback) + if _in_flight then + log.warn('gtasks: operation in progress — please wait') + return + end + _in_flight = true oauth.async(function() local token = oauth.google_client:get_access_token() if not token then + _in_flight = false log.warn('not authenticated — run :Pending auth') return end - callback(token) + local ok, err = pcall(callback, token) + _in_flight = false + if not ok then + log.error('gtasks: ' .. tostring(err)) + end end) end