Created
April 27, 2017 10:07
-
-
Save scorredoira/1d925a58f4bcd9189fc74e2ac5414be5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace web { | |
let global = sync.newMutex(); | |
let locks: Map<sync.Mutex> = <any>{} | |
export function getLockedMutex(key: string): sync.Mutex { | |
global.lock() | |
try { | |
let m = locks[key] | |
if (!m) { | |
m = sync.newMutex() | |
locks[key] = m; | |
} | |
// lock the mutex inside the global lock | |
m.lock(); | |
return m; | |
} | |
finally { | |
global.unlock() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment