Skip to content

Instantly share code, notes, and snippets.

@murjam
murjam / locking.js
Created August 17, 2021 16:50
Locking with redlock bunch of user IDs
/**
* Creates a promise that resolves to either null when no lock was acquired or to user ID if lock was successful
* @param userId
* @returns {Function} async function (promise)
*/
const getLockPromise = (userId) => {
const lockKey = `send-notifications-lock:${userId}`;
return async () => {
try {
### Keybase proof
I hereby claim:
* I am murjam on github.
* I am mikk (https://keybase.io/mikk) on keybase.
* I have a public key ASAxdb2bAh9B3dmxiA9Vftj-n_Ger0-psC8Ii80hOvAbGQo
To claim this, I am signing this object: