完善代码

This commit is contained in:
lyswhut
2021-08-01 13:28:12 +08:00
parent bcf3dde60d
commit c50c747691
9 changed files with 119 additions and 24 deletions
+12 -6
View File
@@ -8,11 +8,8 @@ const { common: COMMON_EVENT_NAME } = require('@main/events/_name')
const { throttle } = require('@common/utils')
let io
// const checkFile = path => {
// fsPromises.access(path, fs.constants.R_OK | fs.constants.W_OK)
// .then(() => console.log('can access'))
// .catch(() => console.error('cannot access'))
// }
let syncingId = null
const wait = (time = 1000) => new Promise((resolve, reject) => setTimeout(resolve, time))
const getRemoteListData = socket => new Promise((resolve, reject) => {
console.log('getRemoteListData')
@@ -379,10 +376,19 @@ const syncList = async socket => {
return handleMergeListDataFromSnapshot(socket, fileData)
}
module.exports = (_io, socket) => {
const checkSyncQueue = async() => {
if (!syncingId) return
await wait()
return checkSyncQueue()
}
module.exports = async(_io, socket) => {
io = _io
await checkSyncQueue()
syncingId = socket.data.keyInfo.clientId
return syncList(socket).then(newListData => {
registerUpdateSnapshotTask(socket, { ...newListData })
return finishedSync(socket)
}).finally(() => {
syncingId = null
})
}