mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Types options.retries with correct type `proper-lockfile` is calling `retry.operation()` underneath so the correct type to use for `LockOptions.retries` is `retry.OperationOptions` and not the more restricted `retry.TimeoutsOptions`. * Adds regression test for #37313
57 lines
1.5 KiB
TypeScript
57 lines
1.5 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
|
|
});
|
|
|
|
lock('', { lockfilePath: 'some/file-lock' })
|
|
.then((release) => release());
|
|
|
|
const release = lockSync('some/file'); // $ExpectType () => void
|
|
release(); // $ExpectType void
|
|
unlockSync('some/file'); // $ExpectType void
|
|
unlockSync('', { lockfilePath: 'some/file-lock' }); // $ExpectType void
|
|
checkSync('some/file'); // $ExpectType boolean
|
|
checkSync('', { lockfilePath: 'some/file-lock' }); // $ExpectType boolean
|
|
|
|
lock('', { retries: 5 });
|
|
lock('', { retries: { retries: 5, factor: 2, minTimeout: 100, randomize: true } });
|
|
|
|
// regression test for #37313
|
|
lock('', { retries: { maxRetryTime: 20, unref: true } });
|