mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import {
|
|
check,
|
|
checkSync,
|
|
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');
|
|
});
|
|
|
|
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
|