Created
October 21, 2019 08:36
-
-
Save bongkook/0364737b0b7d4c316cfb810fca796633 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
var AsyncLock = require('async-lock'); | |
var lock = new AsyncLock(); | |
function operation1() { | |
console.log("Execute operation1"); | |
lock.acquire("key1", function(done) { | |
console.log("lock1 enter") | |
setTimeout(function() { | |
console.log("lock1 Done") | |
done(); | |
}, 3000) | |
}, function(err, ret) { | |
console.log("lock1 release") | |
}, {}); | |
} | |
function operation2() { | |
console.log("Execute operation2"); | |
lock.acquire("key1", function(done) { | |
console.log("lock2 enter") | |
setTimeout(function() { | |
console.log("lock2 Done") | |
done(); | |
}, 2000) | |
}, function(err, ret) { | |
console.log("lock2 release") | |
}, {}); | |
} | |
function operation3() { | |
console.log("Execute operation3"); | |
lock.acquire("key1", function(done) { | |
console.log("lock3 enter") | |
setTimeout(function() { | |
console.log("lock3 Done") | |
done(); | |
}, 100) | |
}, function(err, ret) { | |
console.log("lock3 release") | |
}, {}); | |
}operation1(); operation2(); operation3(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment