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

queue-lemur

v0.0.2

Published

Queue-Lemur nos permite crear colas de tareas de una forma fácil.

Downloads

13

Readme

QueueLemur

QueueLemur es una cola de tareas con soporte para ejecución diferida y persistencia.

Instalación

Para instalar el paquete, utiliza npm: npm install queue-lemur

Uso

A continuación se muestra un ejemplo básico de cómo utilizar QueueLemur en tu proyecto.

Importar y crear una instancia de QueueLemur

import { QueueLemur, QueueLocalMemory } from "queue-lemur";

// Define las opciones de la cola
const options = {
  callback: async (task: any) => {
    // Procesa la tarea
    console.log("Procesando tarea:", task);
  },
  error: (error: Error) => {
    // Maneja errores
    console.error("Error en la tarea:", error.message);
  },
  memory: new QueueLocalMemory<any>(), // Opcional: Puedes proporcionar tu propia implementación de memoria
};

// Crear una instancia de QueueLemur
const queue = new QueueLemur<any>("miCola", options, 2); // La concurrencia es de 2

Agregar tareas a la cola

const task1 = { id: 1, name: "Tarea 1" };
const task2 = { id: 2, name: "Tarea 2" };

// Agregar tarea con una demora de 3 segundos
queue.add("task1", task1, { delay: 3000 });

// Agregar otra tarea con una demora de 5 segundos
queue.add("task2", task2, { delay: 5000 });

Métodos disponibles

add(key: string, task: T, opts?: TaskOptions<T>): Promise<void> Agrega una tarea a la cola con una demora especificada.

  • key: Clave única para la tarea.
  • task: La tarea a agregar.
  • opts: Opciones para la tarea, incluyendo la demora.

opts: TaskOptions<T>

  • callback?: (task: T) => Promise - The action to be executed for each task.
  • error?: (e: any) => void - The error handler for tasks.

getTasks(): Map<string, NodeJS.Timeout> Devuelve el mapa de temporizadores que contiene todas las tareas activas.

getTask(key: string): NodeJS.Timeout | undefined Recupera un temporizador de tarea específico basado en su clave.

getQueue(index: number): T | undefined Recupera una tarea de la cola basada en su índice.

hasQueue(): boolean Comprueba si hay tareas actualmente en la cola.

hasTasks(): boolean Comprueba si hay tareas activas (temporizadores) en ejecución.

getQueueLength(): number Devuelve la longitud de la cola.

getName(): string Devuelve el nombre de la cola.

Posibles Mejoras Adicionales:

  • Logging: Añadir más logging para monitorizar el estado de la cola y las tareas podría ser útil en un entorno de producción.

  • Documentación: Añadir comentarios y documentación para mejorar la mantenibilidad y la comprensión del código.