refactor(sync): centralize with_token in oauth.lua with shared lock
Problem: `with_token` was duplicated in `gcal.lua` and `gtasks.lua`, with the concurrency lock added only to the gtasks copy. Any new backend would silently inherit the same race, and gcal back-to-back push could still create duplicate remote calendar events. Solution: lift `with_token` into `oauth.lua` as `M.with_token(client, name, callback)` behind a module-level `_sync_in_flight` guard. All backends share one implementation; the lock covers gcal, gtasks, and any future backend automatically.
This commit is contained in:
parent
36a5025198
commit
90f1378cb6
3 changed files with 29 additions and 39 deletions
|
|
@ -169,20 +169,8 @@ local function fmt_counts(parts)
|
|||
return table.concat(items, ' | ')
|
||||
end
|
||||
|
||||
---@param callback fun(access_token: string): nil
|
||||
local function with_token(callback)
|
||||
oauth.async(function()
|
||||
local token = oauth.google_client:get_access_token()
|
||||
if not token then
|
||||
log.warn('not authenticated — run :Pending auth')
|
||||
return
|
||||
end
|
||||
callback(token)
|
||||
end)
|
||||
end
|
||||
|
||||
function M.push()
|
||||
with_token(function(access_token)
|
||||
oauth.with_token(oauth.google_client, 'gcal', function(access_token)
|
||||
local calendars, cal_err = get_all_calendars(access_token)
|
||||
if cal_err or not calendars then
|
||||
log.error(cal_err or 'failed to fetch calendars')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue