@kit-p/fastify-tasks
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@kit-p/fastify-tasks

CI NPM version js-standard-style

Add task tracking support for Fastify. The server will not close until all tasks are completed.

@kit-p/fastify-tasks decorates the server interface with the tasks.add and tasks.remove methods for tracking tasks.

Install

npm i @kit-p/fastify-tasks

Quick start

fastify.register is used to register @kit-p/fastify-tasks. By default, It will decorate the fastify object with tasks.add and tasks.remove methods that take an optional argument:

  • the name of the task (does not need to be unqiue)
// index.js:
const fastify = require("fastify")()
const fastifyTasks = require("@kit-p/fastify-tasks")

fastify.register(fastifyTasks)

// named task:
fastify.get("/", (req, reply) => {
  fastify.tasks.add('some-task')
  reply.send('')
  // do some work
  fastify.tasks.remove('some-task')
})

// unnamed task:
fastify.get("/", (req, reply) => {
  fastify.tasks.add()
  reply.send('')
  // do some work
  fastify.tasks.remove()
})

fastify.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log(`server listening on ${fastify.server.address().port}`);
})

Dependencies (1)

Dev Dependencies (8)

Package Sidebar

Install

npm i @kit-p/fastify-tasks

Weekly Downloads

15

Version

2.0.0

License

MIT

Unpacked Size

14 kB

Total Files

15

Last publish

Collaborators

  • kit-p