fastify-locks
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

fastify-locks - A Piscina Locks plugin for Fastify

Example

const fastify = require('fastify')();

fastify.register(require('fastify-locks'), {});

// Declare a route
fastify.get('/', async (request, reply) => {
  await fastify.locks.request('hello', () => {
    // Do something that requires an exclusive lock,
    // such as updating a shared resource.
  });
  reply.send('hello world');
});

// Run the server!
fastify.listen(3000, function (err, address) {
  if (err) {
    fastify.log.error(err);
    process.exit(1);
  }
  fastify.log.info(`server listening on ${address}`);
});

Once registered, the plugin decorates the fastify instance with a new locks property:

  • fastify.locks.request(name[, options], callback)
  • fastify.locks.query()

See the Piscina-locks docs for more information.

The Team

Acknowledgements

Piscina development is sponsored by NearForm Research.

Package Sidebar

Install

npm i fastify-locks

Weekly Downloads

5

Version

3.0.0

License

MIT

Unpacked Size

14.3 kB

Total Files

15

Last publish

Collaborators

  • metcoder95
  • jasnell