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

piperunner

v0.2.3

Published

Run functions against data

Downloads

5

Readme

Piperunner

Manage complex application logic using in memory pipelines.

Composed by three objects:

  1. Pipeline: define a series of functions in order accomplish a job
  2. Runner: run Pipeline against a series of data
  3. Scheduler: run Runner[s] with start/execution/sharing policies

## Install

npm install --save piperunner

Usage

You can use any of the objects independently from the others. See the examples folder for complex examples.

Complete example

let PipeRunner = require('piperunner')
let scheduler = new PipeRunner.Scheduler()

/**
*	Define a scheduler pipeline named
*	'processing_video', and a pipeline
*	*step*.
*/
scheduler.pipeline('processing_video')
.step('first step', (pipeline, job) => {
	console.log('acquiring video ->', job)
	pipeline.next()
})

/**
*	Add another step to the pipeline
*/
scheduler.pipeline('processing_video')
.step('second step', (pipeline, job) => {
	console.log('> publish video ->', job, pipe.env.videoFrameRate)
	pipeline.next()
})

/**
*	Configure the scheduler in order
*	to run the pipeline at the *start.processing.video*
*	event and every 1000 milliseconds
*/
scheduler.run({
	name: 'processing_video',
	run: {
		onEvent: 'start.processing.video',
		everyMs: 1000
	}
})

/**
*	Assign data to the pipelines runner (internal
*	to the scheduler)
*/
scheduler.feed({
	name: 'processing_video', 
	data: [{name: 'video1'}, {name: 'video2'}, {name: 'video3'}] 
})

scheduler.log(true)
scheduler.emit('start.processing.video')

/** Output
*
* Emitting start.processing.video
* Running pipeline processing_video with 1 running process
* acquiring video -> { name: 'video1' }
* > publish video -> { name: 'video1' }
* acquiring video -> { name: 'video2' }
* > publish video -> { name: 'video2' }
* acquiring video -> { name: 'video3' }
* > publish video -> { name: 'video3' }
* 
*/

Scheduler example options

scheduler.run({
	name: 'processing_video',
	run: {
		// will run when this event is emitted
		onEvent: 'start.processing.video',
		// will run when these events are emitted 
		onEvents: ['event1', 'event2'],
		// run every milliseconds
		everyMs: 1000
	},
	on: {
		end: {
			// emit this series of event when the pipeline ends
			emit: ['end.event'],
			// exec these functions then the pipeline ends
			exec: [
				// Pass to another pipeline the data
				(scheduler, pipeline) => { 
					scheduler.assignData('processing_audio', 'audio_frames', pipeline.data().processedAudio)
				}
			]
		}
	}
})

How To

Stop a pipeline

scheduler.stop({name: 'processing_video'})

Ovverride the internal EventEmitter

scheduler.emitter(new EventEmitter)

End a job before reaching the pipe end


let pipe = scheduler.pipeline('processing_video')

pipe.step('maybe', (pipe, job) => {
	if (job.name == 'api1-step1') {
		pipe.end() // Ending 
	} else {
		pipe.next()
	}
})

End the entire runner before time [no processing the other jobs]


let pipe = scheduler.pipeline('processing_video')

pipe.step('maybe', (pipe, job) => {
	if (job.name == 'api1-step1') {
		pipe.endRunner() // Exit the runner 
	} else {
		pipe.next()
	}
})

Pass data between pipe functions


let pipe = scheduler.pipeline('processing_video')

pipe.step('compute data', (pipe, job) => {
	pipe.next('Pass data')
})

pipe.step('need data', (pipe, job, incomingData) => {
	pipe.next('Received data ->', incomingData)
})

Store internal data


let pipe = scheduler.pipeline('processing_video')

pipe.step('compute data', (pipe, job) => {
	pipe.data['customdata'] = 'Yeah'
	pipe.next()
})

pipe.step('need data', (pipe, job,) => {
	pipe.next('Received data ->', pipe.data['customdata'])
})

Set the end callback


let runner = new Runner(jobs, pipe, () => {
	console.log('All Jobs finished')
})