├── test ├── worker.mjs ├── worker.js ├── types │ └── plugin.test-d.ts ├── plugin-esm.test.mjs └── plugin-cjs.test.js ├── example ├── esm │ ├── worker.mjs │ └── server.mjs └── cjs │ ├── worker.js │ └── server.js ├── .github └── workflows │ ├── release.yml │ ├── create-release-pr.yml │ ├── publish.yml │ └── ci.yml ├── plugin.js ├── plugin.d.ts ├── LICENSE ├── CONTRIBUTING ├── README.md ├── .gitignore ├── .npmignore ├── package.json ├── CHANGELOG.md └── CODE_OF_CONDUCT.md /test/worker.mjs: -------------------------------------------------------------------------------- 1 | export default ({ a, b }) => b - a; 2 | -------------------------------------------------------------------------------- /example/esm/worker.mjs: -------------------------------------------------------------------------------- 1 | export default ({ a, b }) => a + b; 2 | -------------------------------------------------------------------------------- /test/worker.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = ({ a, b }) => a + b; 4 | -------------------------------------------------------------------------------- /example/cjs/worker.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = ({ a, b }) => a + b; 4 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | tags: 5 | - 'v[0-9]+.[0-9]+.[0-9]+' 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | contents: write 12 | name: Release Creation 13 | steps: 14 | - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 15 | - uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1.18.0 16 | with: 17 | bodyFile: "CHANGELOG.md" 18 | token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /example/esm/server.mjs: -------------------------------------------------------------------------------- 1 | import { fastify } from 'fastify'; 2 | import * as fastifyPiscina from '../../plugin.js'; 3 | 4 | const app = fastify({ logger: true }); 5 | 6 | app.register(fastifyPiscina, { 7 | // Piscina constructor options 8 | filename: new URL('./worker.mjs', import.meta.url).href 9 | }); 10 | 11 | app.get('/', async (request, reply) => { 12 | reply.send({ hello: `world [${await app.runTask({ a: 1, b: 2 })}]` }); 13 | }); 14 | 15 | // Run the server! 16 | app.listen(3000, function (err, address) { 17 | if (err) { 18 | app.log.error(err); 19 | process.exit(1); 20 | } 21 | }); 22 | -------------------------------------------------------------------------------- /example/cjs/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fastify = require('fastify')({ 4 | logger: true 5 | }); 6 | 7 | const fastifyPiscina = require('../..'); 8 | const { resolve } = require('path'); 9 | 10 | fastify.register(fastifyPiscina, { 11 | // Piscina constructor options 12 | filename: resolve(__dirname, 'worker.js') 13 | }); 14 | 15 | fastify.get('/', async (request, reply) => { 16 | reply.send({ hello: `world [${await fastify.runTask({ a: 1, b: 2 })}]` }); 17 | }); 18 | 19 | // Run the server! 20 | fastify.listen(3000, function (err, address) { 21 | if (err) { 22 | fastify.log.error(err); 23 | process.exit(1); 24 | } 25 | }); 26 | -------------------------------------------------------------------------------- /plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fp = require('fastify-plugin'); 4 | const Piscina = require('piscina'); 5 | const { name } = require('./package.json'); 6 | 7 | function fastifyPiscina (fastify, options, next) { 8 | if (fastify.piscina || fastify.runTask) { 9 | return next(new Error('fastify-piscina has already been registered')); 10 | } 11 | 12 | const pool = new Piscina(options); 13 | 14 | fastify.decorate('piscina', pool); 15 | fastify.decorate('runTask', (...args) => pool.run(...args)); 16 | 17 | next(); 18 | } 19 | 20 | const plugin = fp(fastifyPiscina, { 21 | fastify: '5.x', 22 | name 23 | }); 24 | 25 | module.exports = plugin; 26 | module.exports.default = plugin; 27 | module.exports.fastifyPiscina = plugin; 28 | -------------------------------------------------------------------------------- /.github/workflows/create-release-pr.yml: -------------------------------------------------------------------------------- 1 | name: Create release PR 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | create-pr: 8 | runs-on: ubuntu-latest 9 | 10 | permissions: 11 | contents: write 12 | pull-requests: write 13 | 14 | # Let's try to trigger releases only after this release PR gets merged 15 | # so we might need to verify who the author is to do so 16 | steps: 17 | - uses: googleapis/release-please-action@c2a5a2bd6a758a0937f1ddb1e8950609867ed15c # v4.3.0 18 | with: 19 | # this is a built-in strategy in release-please, see "Action Inputs" 20 | # for more options 21 | release-type: node 22 | skip-github-release: true 23 | skip-labeling: true -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - current 5 | 6 | name: publish 7 | 8 | permissions: 9 | id-token: write # Required for OIDC 10 | contents: read 11 | 12 | jobs: 13 | publish: 14 | if: > 15 | github.event.head_commit.author.username == 'github-actions[bot]' && github.event.head_commit.author.email == '41898282+github-actions[bot]@users.noreply.github.com' 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 19 | - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 20 | with: 21 | node-version: 24 22 | registry-url: 'https://registry.npmjs.org' 23 | - run: npm install -g npm@latest 24 | - run: npm install 25 | - run: npm publish --access public 26 | -------------------------------------------------------------------------------- /plugin.d.ts: -------------------------------------------------------------------------------- 1 | import { FastifyPluginCallback } from 'fastify'; 2 | import { Piscina } from 'piscina'; 3 | 4 | type PiscinaOptions = NonNullable[0]>; 5 | 6 | type FastifyPiscinaPluginType = FastifyPluginCallback; 7 | 8 | declare module 'fastify' { 9 | interface FastifyInstance { 10 | piscina: fastifyPiscina.FastifyPiscinaPool; 11 | runTask: fastifyPiscina.FastifyPiscinaRunTask; 12 | } 13 | } 14 | 15 | declare namespace fastifyPiscina { 16 | export type FastifyPiscinaPool = Piscina; 17 | export type FastifyPiscinaRunTask = Piscina['run']; 18 | 19 | export type FastifyPiscinaPluginOptions = PiscinaOptions; 20 | 21 | export const fastifyPiscina: FastifyPiscinaPluginType; 22 | export { fastifyPiscina as default }; 23 | } 24 | 25 | declare function fastifyPiscina(...params: Parameters): ReturnType; 26 | export = fastifyPiscina; 27 | -------------------------------------------------------------------------------- /test/types/plugin.test-d.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import Fastify, { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; 3 | import { expectError, expectType } from 'tsd'; 4 | import piscinaPlugin, { FastifyPiscinaPool } from '../../plugin'; 5 | 6 | const app: FastifyInstance = Fastify(); 7 | 8 | app.register(piscinaPlugin, { 9 | filename: path.join(__dirname, 'worker.js'), 10 | }); 11 | 12 | // Tsd complains for no reason 13 | // @ts-ignore 14 | app.get('/', async (_request: FastifyRequest, _reply: FastifyReply) => { 15 | return { hello: `world [${await app.runTask({ a: 1, b: 2 })}]` }; 16 | }); 17 | 18 | app.ready(() => { 19 | expectType(app.piscina); 20 | expectType(app.runTask); 21 | }); 22 | 23 | const appThatTriggersTypescriptErrors = Fastify(); 24 | 25 | expectError( 26 | appThatTriggersTypescriptErrors.register(piscinaPlugin, { 27 | unknownOption: 'I will trigger a typescript error', 28 | }) 29 | ); 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 James M Snell and the Piscina contributors 4 | 5 | Piscina contributors listed at https://github.com/jasnell/piscina#the-team and 6 | in the README file. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | # Piscina is an OPEN Open Source Project 2 | 3 | ## What? 4 | 5 | Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 6 | 7 | ## Rules 8 | 9 | There are a few basic ground-rules for contributors: 10 | 11 | 1. **No `--force` pushes** on `master` or modifying the Git history in any way after a PR has been merged. 12 | 1. **Non-master branches** ought to be used for ongoing work. 13 | 1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors. 14 | 1. Internal pull-requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor. 15 | 1. Contributors should attempt to adhere to the prevailing code-style. 16 | 1. 100% code coverage 17 | 1. Semantic Versioning is used. 18 | 19 | ## Releases 20 | 21 | Declaring formal releases remains the prerogative of the project maintainer. 22 | 23 | ## Changes to this arrangement 24 | 25 | This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change. 26 | 27 | ----------------------------------------- 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastify-piscina - A Piscina plugin for Fastify 2 | 3 | ## Example 4 | 5 | ```js 6 | const fastify = require('fastify')(); 7 | const { resolve} = require('path'); 8 | 9 | fastify.register(require('fastify-piscina'), { 10 | // Piscina Options object. See Piscina docs for details 11 | filename: resolve(__dirname, 'worker.js') 12 | }); 13 | 14 | // Declare a route 15 | fastify.get('/', async (request, reply) => { 16 | reply.send({ hello: `world [${await fastify.runTask({ a: 1, b: 2 })}]` }); 17 | }); 18 | 19 | // Run the server! 20 | fastify.listen(3000, function (err, address) { 21 | if (err) { 22 | fastify.log.error(err); 23 | process.exit(1); 24 | } 25 | fastify.log.info(`server listening on ${address}`); 26 | }); 27 | ``` 28 | 29 | Once registered, the plugin decorates the `fastify` instance 30 | with two new properties: 31 | 32 | * `fastify.piscina` {`Piscina`} The Piscina instance. 33 | * `fastify.runTask()` {`Function`} The Piscina runTask function. 34 | 35 | See the [Piscina docs][] for more information. 36 | 37 | ## The Team 38 | 39 | * James M Snell 40 | * Anna Henningsen 41 | * Matteo Collina 42 | 43 | ## Acknowledgements 44 | 45 | Piscina development is sponsored by [NearForm Research][]. 46 | 47 | [Piscina docs]: https://github.com/jasnell/piscina 48 | [NearForm Research]: https://www.nearform.com/research/ 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # 0x 64 | .__browserify_string_empty.js 65 | profile-* 66 | 67 | # JetBrains IntelliJ IDEA 68 | .idea/ 69 | *.iml 70 | 71 | # VS Code 72 | .vscode/ 73 | 74 | # lock files 75 | package-lock.json 76 | yarn.lock 77 | pnpm-lock.yaml 78 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # 0x 64 | .__browserify_string_empty.js 65 | profile-* 66 | 67 | # JetBrains IntelliJ IDEA 68 | .idea/ 69 | *.iml 70 | 71 | # VS Code 72 | .vscode/ 73 | 74 | # lock files 75 | package-lock.json 76 | yarn.lock 77 | 78 | .eslintignore 79 | .eslint* 80 | .gitignore 81 | .git 82 | .github 83 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - current 5 | - next 6 | - 'v*' 7 | pull_request: 8 | 9 | name: CI 10 | 11 | jobs: 12 | lint: 13 | name: Lint 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 17 | - name: Install Node.js 18 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 19 | with: 20 | node-version: v20.x 21 | - name: Install dependencies 22 | run: npm install 23 | - name: Check linting 24 | run: npm run lint 25 | 26 | tests: 27 | needs: [lint] 28 | name: Tests 29 | strategy: 30 | fail-fast: false 31 | matrix: 32 | os: [ubuntu-latest, macos-latest, windows-latest] 33 | node-version: [20.x, 22.x, 24.x] 34 | runs-on: ${{matrix.os}} 35 | steps: 36 | - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 37 | with: 38 | persist-credentials: false 39 | 40 | - name: Use Node.js ${{ matrix.node-version }} 41 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 42 | with: 43 | node-version: ${{ matrix.node-version }} 44 | cache: 'npm' 45 | cache-dependency-path: package.json 46 | 47 | - name: Install Dependencies 48 | run: npm install 49 | - name: Run Tests 50 | run: npm run test:ci 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@piscina/fastify", 3 | "version": "6.0.2", 4 | "description": "A Fastify Piscina Plugin", 5 | "main": "./plugin.js", 6 | "types": "./plugin.d.ts", 7 | "exports": { 8 | "types": "./plugin.d.ts", 9 | "import": "./plugin.js", 10 | "require": "./plugin.js" 11 | }, 12 | "scripts": { 13 | "lint": "standardx \"**/*.{mjs,js,cjs}\" | snazzy", 14 | "lint:fix": "standardx --fix", 15 | "test": "node --test test/*.test.js test/*.test.mjs", 16 | "test:ci": "npm run test && npm run test:typescript", 17 | "test:typescript": "tsd" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/piscinajs/fastify-piscina" 22 | }, 23 | "keywords": [ 24 | "piscina", 25 | "fastify", 26 | "fastify-plugin" 27 | ], 28 | "author": "James M Snell ", 29 | "contributors": [ 30 | "Anna Henningsen ", 31 | "Matteo Collina " 32 | ], 33 | "license": "MIT", 34 | "devDependencies": { 35 | "@types/node": "^24.3.0", 36 | "fastify": "^5.0.0", 37 | "snazzy": "^9.0.0", 38 | "standardx": "^7.0.0", 39 | "tsd": "^0.33.0" 40 | }, 41 | "dependencies": { 42 | "fastify-plugin": "^5.0.0", 43 | "piscina": "^5.1.3" 44 | }, 45 | "eslintConfig": { 46 | "rules": { 47 | "semi": [ 48 | "error", 49 | "always" 50 | ], 51 | "no-unused-vars": "off" 52 | }, 53 | "globals": { 54 | "SharedArrayBuffer": true, 55 | "Atomics": true 56 | } 57 | }, 58 | "standardx": {}, 59 | "tsd": { 60 | "directory": "test/types" 61 | }, 62 | "engines": { 63 | "node": ">=20.x" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/plugin-esm.test.mjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { test } from 'node:test'; 4 | import assert from 'node:assert'; 5 | import Fastify from 'fastify'; 6 | import fastifyPiscina from '../plugin.js'; 7 | 8 | test('It should add decorators - ESM', async (t) => { 9 | const fastify = Fastify(); 10 | await fastify.register(fastifyPiscina, { 11 | filename: new URL('./worker.mjs', import.meta.url).href 12 | }); 13 | 14 | t.after(() => fastify.close()); 15 | 16 | assert.ok(fastify.piscina); 17 | assert.ok(fastify.piscina.run); 18 | assert.ok(fastify.runTask); 19 | 20 | fastify.get('/', async (request, reply) => { 21 | reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) }); 22 | }); 23 | 24 | await fastify.ready(); 25 | }); 26 | 27 | test('It should throw when trying to register the plugin more than once - ESM', async () => { 28 | const fastify = Fastify(); 29 | fastify.register(fastifyPiscina).register(fastifyPiscina); 30 | 31 | await assert.rejects( 32 | fastify.ready(), 33 | { message: 'fastify-piscina has already been registered' } 34 | ); 35 | }); 36 | 37 | test('It should be able to use `fastify.runTask()` - ESM', async (t) => { 38 | const fastify = Fastify(); 39 | await fastify.register(fastifyPiscina, { 40 | filename: new URL('./worker.mjs', import.meta.url).href 41 | }); 42 | 43 | t.after(() => fastify.close()); 44 | 45 | fastify.get('/', async (request, reply) => { 46 | reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) }); 47 | }); 48 | 49 | await fastify.ready(); 50 | 51 | const response = await fastify.inject({ 52 | method: 'GET', 53 | path: '/' 54 | }); 55 | const payload = JSON.parse(response.payload); 56 | assert.strictEqual(payload.result, 1); 57 | }); 58 | -------------------------------------------------------------------------------- /test/plugin-cjs.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { resolve } = require('path'); 4 | const { test } = require('node:test'); 5 | const assert = require('node:assert'); 6 | const Fastify = require('fastify'); 7 | const fastifyPiscina = require('../plugin'); 8 | 9 | test('It should add decorators - CommonJS', async (t) => { 10 | const fastify = Fastify(); 11 | await fastify.register(fastifyPiscina, { 12 | filename: resolve(__dirname, 'worker.js') 13 | }); 14 | 15 | t.after(() => fastify.close()); 16 | 17 | assert.ok(fastify.piscina); 18 | assert.ok(fastify.piscina.run); 19 | assert.ok(fastify.runTask); 20 | 21 | fastify.get('/', async (request, reply) => { 22 | reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) }); 23 | }); 24 | 25 | await fastify.ready(); 26 | }); 27 | 28 | test('It should throw when trying to register the plugin more than once - CommonJS', async () => { 29 | const fastify = Fastify(); 30 | fastify 31 | .register(fastifyPiscina) 32 | .register(fastifyPiscina); 33 | 34 | await assert.rejects( 35 | fastify.ready(), 36 | { message: 'fastify-piscina has already been registered' } 37 | ); 38 | }); 39 | 40 | test('It should be able to use `fastify.runTask()` - CommonJS', async (t) => { 41 | const fastify = Fastify(); 42 | await fastify.register(fastifyPiscina, { 43 | filename: resolve(__dirname, 'worker.js') 44 | }); 45 | 46 | t.after(() => fastify.close()); 47 | 48 | fastify.get('/', async (request, reply) => { 49 | reply.send({ result: await fastify.runTask({ a: 1, b: 2 }) }); 50 | }); 51 | 52 | await fastify.ready(); 53 | 54 | const response = await fastify.inject({ 55 | method: 'GET', 56 | path: '/' 57 | }); 58 | const payload = JSON.parse(response.payload); 59 | assert.strictEqual(payload.result, 3); 60 | }); 61 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [6.0.2](https://github.com/piscinajs/fastify-piscina/compare/v6.0.1...v6.0.2) (2025-09-03) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * add provenance ([95e66b4](https://github.com/piscinajs/fastify-piscina/commit/95e66b467f4df179a45a01c5baf3a88a32cc79a2)) 11 | 12 | ## [6.0.1](https://github.com/piscinajs/fastify-piscina/compare/v6.0.0...v6.0.1) (2025-08-28) 13 | 14 | 15 | ### Bug Fixes 16 | 17 | * add provenance ([8b00441](https://github.com/piscinajs/fastify-piscina/commit/8b00441ed7b9af32e7f124924954423e98e74712)) 18 | 19 | ## [6.0.0](https://github.com/piscinajs/fastify-piscina/compare/v5.0.0...v6.0.0) (2025-08-27) 20 | 21 | 22 | ### ⚠ BREAKING CHANGES 23 | 24 | * namespace piscina projects 25 | * update plugin for fastify v5 and fix types (#15) 26 | 27 | ### Features 28 | 29 | * namespace piscina projects ([4f20a28](https://github.com/piscinajs/fastify-piscina/commit/4f20a283271a02f53f27756ff4e761ebd84cc5ec)) 30 | * update plugin for fastify v5 and fix types ([#15](https://github.com/piscinajs/fastify-piscina/issues/15)) ([c58d2d8](https://github.com/piscinajs/fastify-piscina/commit/c58d2d8257a46da4762c59966123e6acab0c7dcf)) 31 | 32 | ## [5.0.0](https://github.com/piscinajs/fastify-piscina/compare/v4.0.0...v5.0.0) (2023-11-26) 33 | 34 | 35 | ### ⚠ BREAKING CHANGES 36 | 37 | * v5 (#12) (#13) 38 | 39 | ### Features 40 | 41 | * add tests to the plugin ([9bff135](https://github.com/piscinajs/fastify-piscina/commit/9bff13512c6bc9a3954faa9b766f43e75eb27321)) 42 | * fail fast if `fastify-piscina` has already been registered ([6b39e16](https://github.com/piscinajs/fastify-piscina/commit/6b39e167d367d99b345d6e6d90ed6dd3e6510b55)) 43 | * Merge pull request [#11](https://github.com/piscinajs/fastify-piscina/issues/11) from darkgl0w/fix-and-features ([e048210](https://github.com/piscinajs/fastify-piscina/commit/e04821061762c56ec84e085e2edf7e6bc8496b7b)) 44 | * v5 ([#12](https://github.com/piscinajs/fastify-piscina/issues/12)) ([#13](https://github.com/piscinajs/fastify-piscina/issues/13)) ([2b93bcc](https://github.com/piscinajs/fastify-piscina/commit/2b93bccf10ce460c0670743a27ab6e70634a17d1)) 45 | 46 | 47 | ### Bug Fixes 48 | 49 | * swap from `pool.runTask()` to `pool.run()` ([c5ebb09](https://github.com/piscinajs/fastify-piscina/commit/c5ebb09d095b48ce5d72f1ded1dd703c7c1b533d)) 50 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | jasnell@gmail.com, anna@addaleax.net, or matteo.collina@gmail.com. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | --------------------------------------------------------------------------------