本文整理汇总了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
})();
示例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();
}
}
}
示例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');
});