当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript proper-lockfile.lock函数代码示例

本文整理汇总了TypeScript中proper-lockfile.lock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript lock函数的具体用法?TypeScript lock怎么用?TypeScript lock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lock函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: lock

(async () => {
    const release = await lock('some/file'); // $ExpectType () => Promise<void>
    await release(); // $ExpectType void

    await lock('some/file'); // $ExpectType () => Promise<void>
    await unlock('some/file'); // $ExpectType void

    await check('some/file'); // $ExpectType boolean
})();
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:9,代码来源:proper-lockfile-tests.ts

示例2: runInit

  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();
      }
    }
  }
开发者ID:elastic,项目名称:kibana,代码行数:34,代码来源:workspace_command.ts

示例3: lock

    lockSync,
    unlock,
    unlockSync
} from 'proper-lockfile';

(async () => {
    const release = await lock('some/file'); // $ExpectType () => Promise<void>
    await release(); // $ExpectType void

    await lock('some/file'); // $ExpectType () => Promise<void>
    await unlock('some/file'); // $ExpectType void

    await check('some/file'); // $ExpectType boolean
})();

lock('some/file')
    .then((release) => {
        // Do something while the file is locked

        // Call the provided release function when you're done,
        // which will also return a promise
        return release();
    });

lock('some/file')
    .then(() => {
        // Do something while the file is locked

        // Later..
        return unlock('some/file');
    });
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:31,代码来源:proper-lockfile-tests.ts


注:本文中的proper-lockfile.lock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。