I have nodejs app - version 10 and i installed Mutex library
https://www.npmjs.com/package/async-mutex
Following their instructions on npmjs i installed the npm package and tried to require
npm i async-mutex
var Mutex = require('async-mutex').Mutex;
after that when i start with their example:
mutex
.acquire()
.then(function(release) {
// ...
});
i get
mutex is not defined ERROR
How can i solve this problem ? The npm packages is properly installed and i tried the following:
var mutex = require('async-mutex').Mutex
then i get mutex.acquire is not a function error
You are missing ONE IMPORTANT part in their documentation:
const mutex = new Mutex();
So you need to do:
var Mutex = require('async-mutex').Mutex;
var mutex = new Mutex();
Now you can use mutex.acquire()
. Note: NOT Mutex.acquire()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.