本文整理匯總了TypeScript中proper-lockfile.check函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript check函數的具體用法?TypeScript check怎麽用?TypeScript check使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了check函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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();
}
}
}
示例2: 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
})();
示例3: check
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');
});
check('some/file')
.then((isLocked) => {
// isLocked will be true if 'some/file' is locked, false otherwise
});
const release = lockSync('some/file'); // $ExpectType () => void
release(); // $ExpectType void
unlockSync('some/file'); // $ExpectType void
checkSync('some/file'); // $ExpectType boolean