Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@carmen0208/micro-batcher
Advanced tools
MicroBatcher is a library that allows you to process jobs in batches, providing a more efficient way of handling multiple jobs simultaneously.
MicroBatcher is a library that allows you to process jobs in batches, providing a more efficient way of handling multiple jobs simultaneously.
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!
To install the MicroBatcher library, you can use npm:
npm install @carmen0208/micro-batcher
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
});
submitJob(job: T): JobResult<T>
Submits a single job to the micro-batcher for processing.
job
- The job to be processed.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.
JobResult
objects representing the status of each job.shutdown(): Promise<JobResult<T>[]>
Shutdowns the micro-batcher and processes all remaining jobs.
FAQs
MicroBatcher is a library that allows you to process jobs in batches, providing a more efficient way of handling multiple jobs simultaneously.
We found that @carmen0208/micro-batcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.