Skip to content

piscinajs/fastify-piscina

current
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

fastify-piscina - A Piscina plugin for Fastify

Example

const fastify = require('fastify')();
const { resolve} = require('path');

fastify.register(require('fastify-piscina'), {
  // Piscina Options object. See Piscina docs for details
  filename: resolve(__dirname, 'worker.js')
});

// Declare a route
fastify.get('/', async (request, reply) => {
  reply.send({ hello: `world [${await fastify.runTask({ a: 1, b: 2 })}]` });
});

// Run the server!
fastify.listen(3000, function (err, address) {
  if (err) {
    fastify.log.error(err);
    process.exit(1);
  }
  fastify.log.info(`server listening on ${address}`);
});

Once registered, the plugin decorates the fastify instance with two new properties:

  • fastify.piscina {Piscina} The Piscina instance.
  • fastify.runTask() {Function} The Piscina runTask function.

See the Piscina docs for more information.

The Team

Acknowledgements

Piscina development is sponsored by NearForm Research.

About

A Piscina plugin for Fastify

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published