refactor: address adversarial widget architecture review
This commit is contained in:
1 parent
0ca62f1232
commit
9bf266935b
42 files changed
+460
-578
No files matched your search
@@ -16,6 +16,7 @@ describe("createLockChannel", () => {
|
||||
|
||||
expect(token).toEqual(expect.any(String));
|
||||
if (!token) throw new Error("Expected the fallback lock to return a token");
|
||||
await expect(lock.renewAsync(token, 60)).resolves.toBe(true);
|
||||
await expect(lock.releaseAsync(token)).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -155,6 +155,19 @@ export const createLockChannel = (name: string) => {
|
||||
const result = await client.set(name, token, "EX", ttlSeconds, "NX");
|
||||
return result === "OK" ? token : null;
|
||||
},
|
||||
renewAsync: async (token: string, ttlSeconds: number) => {
|
||||
const client = getSetClient;
|
||||
if (!client) return true;
|
||||
|
||||
const result = await client.eval(
|
||||
"if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('expire', KEYS[1], ARGV[2]) else return 0 end",
|
||||
1,
|
||||
name,
|
||||
token,
|
||||
ttlSeconds,
|
||||
);
|
||||
return result === 1;
|
||||
},
|
||||
releaseAsync: async (token: string) => {
|
||||
const client = getSetClient;
|
||||
if (!client) return;
|
||||
|
||||
Reference in new issue
Block a user