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

@carmen0208/micro-batcher

v0.1.2

Published

MicroBatcher is a library that allows you to process jobs in batches, providing a more efficient way of handling multiple jobs simultaneously.

Downloads

16

Readme

MicroBatcher

MicroBatcher is a library that allows you to process jobs in batches, providing a more efficient way of handling multiple jobs simultaneously.

Building the Source

To build the source code, follow these steps:

npm install #Build the project using the following command:
npm run build #This will compile the TypeScript code into JavaScript and generate the necessary artifacts in the dist directory.
npm test #Run the tests to ensure everything is working correctly by executing the following command:

Note: Before running the tests, make sure you have the necessary test dependencies installed.

After successful execution of the build and tests, you are ready to use the library!

Installation

To install the MicroBatcher library, you can use npm:

npm install @carmen0208/micro-batcher

Usage

Here is an example of how you can use the MicroBatcher library:

import { MicroBatcher, JobResult, JobStatus } from '@carmen0208/micro-batcher';

// Define your batch processor function
const batchProcessor = async (jobs: number[]): Promise<JobResult<number>[]> => {
  // Implement your batch processing logic here
};

// Create an instance of MicroBatcher
const config = { maxBatchSize: 3, maxWaitTimeMs: 5000 };
const microBatcher = new MicroBatcher<number>(batchProcessor, config);

// Submit jobs to the micro-batcher
const job1 = 1;
const job2 = 2;
const job3 = 3;

const result1 = microBatcher.submitJob(job1);
const result2 = microBatcher.submitJob(job2);
const result3 = microBatcher.submitJob(job3);

// Get the current status of all jobs
const jobProcessResult = microBatcher.getJobProcessResult();

// Shutdown the micro-batcher to process any remaining jobs
microBatcher.shutdown().then((finishedJobs) => {
  // Handle the finished jobs
});

API

submitJob(job: T): JobResult<T>

Submits a single job to the micro-batcher for processing.

  • job - The job to be processed.
  • Returns a JobResult object representing the status of the submitted job. The returned promise resolves with the job result.

getJobProcessResult(): JobResult<T>[]

Returns the current status of all jobs in the micro-batcher. This method combines the jobs from the jobs pool and the finished jobs.

  • Returns an array of JobResult objects representing the status of each job.

shutdown(): Promise<JobResult<T>[]>

Shutdowns the micro-batcher and processes all remaining jobs.

  • Returns a promise that resolves when all jobs have been processed.