Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

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

About

Tasks tracking plugin for fastify

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /