Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kit-p/fastify-tasks
Tasks tracking plugin for fastify
https://github.com/kit-p/fastify-tasks
fastify fastify-plugin javascript
Last synced: 2 months ago
JSON representation
Tasks tracking plugin for fastify
- Host: GitHub
- URL: https://github.com/kit-p/fastify-tasks
- Owner: Kit-p
- License: mit
- Created: 2024-09-07T14:34:29.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-25T02:53:41.000Z (3 months ago)
- Last Synced: 2024-10-12T22:02:43.342Z (2 months ago)
- Topics: fastify, fastify-plugin, javascript
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @kit-p/fastify-tasks
![CI](https://github.com/Kit-p/fastify-tasks/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@kit-p/fastify-tasks.svg?style=flat)](https://www.npmjs.com/package/@kit-p/fastify-tasks)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)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)
```js
// 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}`);
})
```