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

1.0.1 • 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}`);
})

Readme

Keywords

Package Sidebar

Install

npm i @kit-p/fastify-tasks

Weekly Downloads

13

Version

1.0.1

License

MIT

Unpacked Size

14 kB

Total Files

15

Last publish

Collaborators

  • kit-p