3.0.7 • Published 11 months ago

@prairielearn/named-locks v3.0.7

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

@prairielearn/named-locks

Uses Postgres row-level locks to grant exclusive access to resources.

Usage

You must first call init with Postgres connection details and an idle error handler:

import { init } from '@prairielearn/named-locks';

await init(
  {
    user: 'postgres',
    // ... other Postgres config
  },
  (err) => {
    throw err;
  },
);

You can then obtain a lock and do work while it is held. The lock will be automatically released once the provided function either resolves or rejects.

import { doWithLock } from '@prairielearn/named-locks';

await doWithLock('name', {}, async () => {
  console.log('Doing some work');
});

Optionally, you may configure the lock to automatically "renew" itself by periodically making no-op queries in the background. This is useful for operations that may take longer than the configured Postgres idle session timeout.

import { doWithLock } from '@prairielearn/named-locks';

await doWithLock(
  'name',
  {
    autoRenew: true,
  },
  async () => {
    console.log('Doing some work');
  },
);
3.0.4

1 year ago

3.0.3

1 year ago

3.0.7

11 months ago

3.0.6

11 months ago

3.0.5

12 months ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.5.11

1 year ago

1.5.10

1 year ago

1.5.9

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago