How to use the proper-lockfile.lock function in proper-lockfile

To help you get started, we’ve selected a few proper-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 elastic / kibana / x-pack / plugins / code / server / lsp / workspace_command.ts View on Github external
public async runInit(force: boolean) {
    if (this.repoConfig.init) {
      const versionFile = path.join(this.workspaceDir, 'init.version');
      if (this.checkRevision(versionFile) && !force) {
        this.log.info('a same revision exists, init cmd skipped.');
        return;
      }
      const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');

      const isLocked = await LockFile.check(lockFile);
      if (isLocked) {
        this.log.info('another process is running, please try again later');
        return;
      }
      const release = await LockFile.lock(lockFile);

      try {
        const process = this.spawnProcess(this.repoConfig.init);
        const logFile = path.join(this.workspaceDir, 'init.log');
        const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
        this.redirectOutput(process.stdout, logFileStream);
        this.redirectOutput(process.stderr, logFileStream, true);
        process.on('close', async (code, signal) => {
          logFileStream.close();
          await this.writeRevisionFile(versionFile);
          this.log.info(`init process finished with code: ${code} signal: ${signal}`);
          await release();
        });
      } catch (e) {
        this.log.error(e);
        release();
github fulcrumapp / fulcrum-desktop / resources / yarn / yarn / lib-legacy / cli / index.js View on Github external
return new (_promise || _load_promise()).default(ok => {
    const lockFilename = mutexFilename || path.join(config.cwd, (_constants || _load_constants()).SINGLE_INSTANCE_FILENAME);
    lockfile.lock(lockFilename, { realpath: false }, (err, release) => {
      if (err) {
        if (isFirstTime) {
          reporter.warn(reporter.lang('waitingInstance'));
        }
        setTimeout(() => {
          ok(runEventuallyWithFile(mutexFilename, isFirstTime));
        }, 200); // do not starve the CPU
      } else {
        onDeath(() => {
          process.exit(1);
        });
        ok(run().then(release));
      }
    });
  });
};
github esy / esy / esy-install / src / bin / runYarnCommand.js View on Github external
return new Promise(resolve => {
      const lockFilename =
        mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
      lockfile.lock(
        lockFilename,
        {realpath: false},
        (err: mixed, release: () => void) => {
          if (err) {
            if (isFirstTime) {
              ctx.reporter.warn(ctx.reporter.lang('waitingInstance'));
            }
            setTimeout(() => {
              resolve(runEventuallyWithFile(mutexFilename, false));
            }, 200); // do not starve the CPU
          } else {
            onDeath(() => {
              process.exitCode = 1;
            });
            resolve(run().then(release));
          }
github LinusU / vscode-auto-dark-mode / index.js View on Github external
async function switchTheme (target) {
  const lockfile = require('proper-lockfile')

  let release
  try {
    release = await lockfile.lock('', { lockfilePath })
  } catch (err) {
    if (err.code === 'ELOCKED') {
      // Another
      return
    }

    throw err
  }

  try {
    const colorTheme = workspace.getConfiguration('autoDarkMode').get(`${target}Theme`)
    workspace.getConfiguration('workbench').update('colorTheme', colorTheme, ConfigurationTarget.Global)

    const iconTheme = workspace.getConfiguration('autoDarkMode').get(`${target}IconTheme`)
    if (iconTheme) {
      workspace.getConfiguration('workbench').update('iconTheme', iconTheme, ConfigurationTarget.Global)
github yarnpkg / yarn / src / cli / index.js View on Github external
return new Promise(resolve => {
      const lockFilename = mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
      lockfile.lock(lockFilename, {realpath: false}, (err: mixed, release: (() => void) => void) => {
        if (err) {
          if (isFirstTime) {
            reporter.warn(reporter.lang('waitingInstance'));
          }
          setTimeout(() => {
            resolve(runEventuallyWithFile(mutexFilename, false));
          }, 200); // do not starve the CPU
        } else {
          onDeath(() => {
            process.exitCode = 1;
          });
          resolve(run().then(() => new Promise(resolve => release(resolve))));
        }
      });
    });
  };
github atomist / sdm-core / lib / internal / preferences / FilePreferenceStore.ts View on Github external
private async doWithPreferenceFile(withPreferenceFile: WithPreferenceFile): Promise {
        await lock(this.filePath, { retries: 5 });
        const prefs = await this.read();
        let result;
        try {
            result = await withPreferenceFile(prefs);
            if (result.save) {
                await fs.writeJson(this.filePath, prefs);
            }
        } catch (e) {
            logger.error(`Operation on preference file failed: ${e.message}`);
        }
        await unlock(this.filePath);
        return result.value as V;
    }
github tus / tus-js-client / lib / node / storage.js View on Github external
setItem(key, value, cb) {
    lockfile.lock(this.path, this._lockfileOptions(), (err, release) => {
      if (err) {
        return cb(err);
      }

      cb = this._releaseAndCb(release, cb);
      this._getData((err, data) => {
        if (err) {
          return cb(err);
        }

        data[key] = value;
        this._writeData(data, (err) => cb(err));
      });
    });
  }

proper-lockfile

A inter-process and inter-machine lockfile utility that works on a local or network file system

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis