errorception / redis-lock

Implements a locking primitive using redis. An implementation of the algorithm described at https://redis.io/commands/setnx
211 stars 48 forks source link

feat: add type definition #37

Open dojineko opened 1 year ago

dojineko commented 1 year ago

Added TypeScript type definitions for redis-lock 1.0.0

fix: https://github.com/errorception/redis-lock/issues/36 ref: https://github.com/misskey-dev/misskey/pull/9971

The following is a record of how JSDoc handles this issue. If it is necessary, I would like to change the means of implementation.

```diff + /** + * @param {import('redis').RedisClientType} client + * @param {string} lockName + * @param {number} timeout + * @param {number} retryDelay + * @param {(timeout: number) => void} onLockAcquired + */ async function acquireLock (client, lockName, timeout, retryDelay, onLockAcquired) { ``` ```diff + /** + * @param {import('redis').RedisClientType} client + * @param {number} retryDelay + */ function redisLock (client, retryDelay = DEFAULT_RETRY_DELAY) { ``` ```diff + /** + * @param {string} lockName + * @param {number} timeout + * @returns {Promise} + */ async function lock (lockName, timeout = DEFAULT_TIMEOUT) { ```
rostamiani commented 1 year ago

The function output is not a Promise<string | undefined>, It's a function and should be Promise<() => Promise<void>>