How to use the lockfile.lock function in lockfile

To help you get started, we’ve selected a few lockfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github owid / owid-grapher / js / screenshot.js View on Github external
additionalFlags: [
      '--window-size=1020,720',
      '--disable-gpu',
      '--headless'
    ]
  });

  return launcher.run().then(() => launcher)
    .catch(err => {
      return launcher.kill().then(() => { // Kill Chrome if there's an error.
        throw err;
      }, console.error);
    });
}

lockfile.lock(output+'.lock', function(err) {
  if (err) {
    // Another process is already working on this. Just wait until it's finished.
    console.log("Waiting for other process")
    lockfile.lock(output+'.lock', { wait: timeout }, function(err) {
        process.exit(0)
    })
  } else {
    run().catch(e => {
      if (e.code == "ECONNREFUSED") {
        launchChrome().then(run).catch(e => {
          console.error(e);
          process.exit(1);
        })
      } else {
        console.error(e);
        process.exit(1);
github GUI / uas-parser / lib / updater.js View on Github external
initialize: function(updateInterval, callback) {
    this.updateInterval = updateInterval;
    this.updateCallback = callback;

    // Perform a lock while updating the cache to ensure only one process
    // is updating the cache at a time.
    lockFile.lock(this.cacheLockPath, { stale: 60 * 1000 }, function(error) {
      if(error) {
        this.finish(null, cache);
        return true;
      }

      fs.stat(this.cachePath, this.handleFileStat.bind(this));
    }.bind(this));
  },
github manifoldco / torus-cli / cli / lib / util / lock.js View on Github external
return new Promise(function (resolve, reject) {
    var lockPath = getLockPath(file);

    /* eslint-disable consistent-return */
    lockfile.lock(lockPath, function (err) {
      if (err) {
        return reject(err);
      }

      resolve();
    });
  });
};
github marklagendijk / WinLess / WinLess / node_modules / npm / lib / cache.js View on Github external
function then () {
    var opts = { stale: npm.config.get("cache-lock-stale")
               , retries: npm.config.get("cache-lock-retries")
               , wait: npm.config.get("cache-lock-wait") }
    var lf = lockFileName(u)
    log.verbose("lock", u, lf)
    lockFile.lock(lf, opts, function(er) {
      if (!er) myLocks[lf] = true
      cb(er)
    })
  }
}
github MobileChromeApps / mobile-chrome-apps / node_modules / cordova / node_modules / npm / lib / cache.js View on Github external
function then () {
    var opts = { stale: npm.config.get("cache-lock-stale")
               , retries: npm.config.get("cache-lock-retries")
               , wait: npm.config.get("cache-lock-wait") }
    var lf = lockFileName(u)
    log.verbose("lock", u, lf)
    lockFile.lock(lf, opts, function(er) {
      if (!er) myLocks[lf] = true
      cb(er)
    })
  }
}
github angelozerr / tern.java / eclipse / tern.eclipse.ide.server.nodejs.embed.linux.gtk.x86 / nodejs / node-v0.10.22-linux-x86 / lib / node_modules / npm / lib / cache.js View on Github external
getCacheStat(function (er, cs) {
    if (er) return cb(er)
    var opts = { stale: npm.config.get("cache-lock-stale")
               , retries: npm.config.get("cache-lock-retries")
               , wait: npm.config.get("cache-lock-wait") }
    var lf = lockFileName(u)
    log.verbose("lock", u, lf)
    lockFile.lock(lf, opts, function(er) {
      if (!er) myLocks[lf] = true
      cb(er)
    })
  })
}
github rjanicek / bos / scripts / bos-core.js View on Github external
lockMutex: function (done) {
	    	lockFile.lock(mutexPath, function (error) {
				if (error && error.code === 'EEXIST') {
					error.description = 'Could not open data store because files are locked by another instance. If no other instance, manually delete ' + error.path;
				}
				done(error);
	    	});
	    },
	    loadData: ['lockMutex', function (done) {
github NREL / api-umbrella / lib / config.js View on Github external
saveRuntime: function(callback) {
    lockFile.lock(this.runtimeLockPath, {}, function() {
      var data = yaml.safeDump(this.runtimeValues || {});
      logger.info('Writing new config (PID ' + process.pid + ')...');
      logger.debug(data);
      atomic.writeFile(this.runtimePath, data, function(error) {
        if(callback) {
          callback(error);
        }
      });

    }.bind(this));
  },
github GUI / http-stale-cache-proxy / lib / http-stale-cache-proxy.js View on Github external
respondFromCache: function(callback) {
    logger.info(this.requestLogId + ' - Delivering cached response');

    lockfile.lock(this.lockCachePath, { wait: 500, stale: 60000 }, function(error) {
      callback(error);

      fs.readFile(this.metaCachePath, function(error, data) {
        var metadata = JSON.parse(data);
        this.response.writeHead(metadata.statusCode, metadata.headers);

        var bodyFile = fs.createReadStream(this.bodyCachePath);
        bodyFile.pipe(this.response);
        bodyFile.on('end', function() {
          lockfile.unlock(this.lockCachePath, function() {
          });
        }.bind(this));
      }.bind(this));
    }.bind(this));
  },

lockfile

A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.

ISC
Latest version published 6 years ago

Package Health Score

55 / 100
Full package analysis

Popular lockfile functions