mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #16644 from overleaf/em-promisify-update-manager
Promisify UpdateManager GitOrigin-RevId: 2c3e21ee6ef2454f79695ca8623c3d38720ff6bf
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { promisify } = require('util')
|
||||
const metrics = require('@overleaf/metrics')
|
||||
const logger = require('@overleaf/logger')
|
||||
const os = require('os')
|
||||
@@ -64,6 +65,27 @@ module.exports = class RedisLocker {
|
||||
|
||||
// read-only copy for unit tests
|
||||
this.unlockScript = UNLOCK_SCRIPT
|
||||
|
||||
this.promises = {
|
||||
checkLock: promisify(this.checkLock.bind(this)),
|
||||
getLock: promisify(this.getLock.bind(this)),
|
||||
releaseLock: promisify(this.releaseLock.bind(this)),
|
||||
|
||||
// tryLock returns two values: gotLock and lockValue. We need to merge
|
||||
// these two values into one for the promises version.
|
||||
tryLock: id =>
|
||||
new Promise((resolve, reject) => {
|
||||
this.tryLock(id, (err, gotLock, lockValue) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else if (!gotLock) {
|
||||
resolve(null)
|
||||
} else {
|
||||
resolve(lockValue)
|
||||
}
|
||||
})
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Use a signed lock value as described in
|
||||
|
||||
Reference in New Issue
Block a user