npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@autotelic/fastify-queue

v0.2.0

Published

an async queue for fastify

Downloads

52

Readme

fastify-queue

An async queue for Fastify.

Usage

npm i @autotelic/fastify-queue

Example

const fastifyQueue = require('@autotelic/fastify-queue')

function myRoute (fastify, opts) {
  fastify.register(fastifyQueue)

  fastify.post('/example', async (request, reply) => {
    reply.queue.add('async-action-one', reply.asyncAction())
    reply.queue.add('async-action-two', reply.asyncActionTwo())
    reply.queue.add('async-action-three', reply.asyncActionThree())
    // Manual resolution optional - queue will otherwise resolve in onResponse hook.
    const results = await reply.queue.resolve()
    reply.status(200)
  })
}

API

Plugin opts

fastify-queue accepts the following optional configuration:

  • initializer: (key: string, value: any, reply: FastifyReply) => any | Promise<any>

    • Called each time an item is added to the queue. The value returned will be the value added to the queue.
  • resolver: (key: string, value: any, reply: FastifyReply) => any

    • Called each time an item in the queue is resolved. value is the resolved value of an item in the queue.
  • onError: (error: Error, reply: FastifyReply) => any

    • Called if an error occurs while resolving the queue. Defaults to fastify.log.error(error).
  • onResolved: (result: any, reply: FastifyReply) => void

    • Called after the queue has successfully resolved. result is the resolved queue.
  • queueName: string

    • Determines the name of the reply decorator added by the plugin. Defaults to 'queue'.
  • concurrency: number

    • Max number of concurrently pending promises. Defaults to Infinity.
    • This value is passed directly to p-props options param.
  • stopOnError: boolean

    • When set to false, errors thrown while resolving items in the queue will be accumulated. Once all items in the queue have settled, a single aggregated error will be thrown.
    • This value is passed directly to p-props options param.

Reply Decorator

fastify-queue adds a queue (or the value of opts.queueName) reply decorator containing the following properties:

  • add: (key: string, value: any) => void

    • Used to add items to the queue.
  • resolve: (cb?: (result: any, reply: FastifyReply) => void) => void

    • Used to manually resolve the queue. cb defaults to opts.onResolved.
    • fastify-queue will automatically resolve the queue in an onResponse hook, if this has not already been called.
  • contents: Map

    • The queue Map instance.