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

ergate

v2.0.11

Published

ergate

Downloads

26

Readme

Eragte

Ergate is a npm package for better use ChildProcess and ThreadWorker in typescript. By using Ergate, you don't need to create childProcess or worker in trandition way:

fork("xxxx/xxxx/xxxx.js")
new Worker("xxxx/xxxx/xxxx.js")

The simple example usage like this:

const proc = await Process(TestProcessClass)
const sum: number = await proc.testFunction(111, 222, 333)
console.log('testFunction sum', sum)
proc.testCallbackFunction(5, 6, (sum, timestamp) => {
	console.log('testCallbackFunction sum and timestamp', sum, timestamp)
})
proc.on('property-changed', (property, value) => {
	console.log('Child process class property changed', property, value)
	console.log('Current property value', proc.testProperty)
	//Close the child process
	proc.terminate().then(() => {
		console.log('Child process closed')
	})
})
proc.testProperty = "this is assigned property"

The TestProcessClass is a typescript class which exteneds ProcessClass

export class TestProcessClass extends ProcessClass {
    public testProperty: string = "this is test property string"

    public testCallbackFunction(a: number, b: number, callback: (sum: number, timestamp: number) => void) {
	    callback(a + b, Date.now())
    }

    public async testFunction(a: number, b: number, c: number) {
    	return a + b + c
    }

	protected async setup(): Promise<void> {
		console.log('This is log from child process')
    }
}

Then run this example, you will get the following retults:

This is log from child process
testFunction sum 666
testCallbackFunction sum and timestamp 11 1602350870867
Child process class property changed testProperty this is assigned property
Current property value this is assigned property
Child process closed

Both ChildProcess and WorkerThreads are created in similar way, the difference between create childProcess and workerThread is the base class your custom class have extended are differnet.

The Base process class example

export class YourProcessClass extends ProcessClass {
    protected async setup(): Promise<void> {
    	//the code will be executed while the childProcess initialized
    }
}

The Base thread class example

export class YourThreadClass extends ThreadClass {
    protected async setup(): Promise<void> {
    	//the code will be executed while the thread worker initialized
    }
}

Create a process

const yourProcessClassInstance = await Process(YourProcessClass)

now you can use "yourProcessClassInstance" just like a local class instance

Create a thread

const yourThreadClassInstance = await Thread(YourThreadClass)

now you can use "yourThreadClassInstance" just like a local class instance

API

ProcessClass and ThreadClass are both extended ErgateBaseClass, therefore, you can invoke terminate() function for terminate process/worker

Some common function will injected into your own class:

async setup(): Promise

async terminate(): Promise

EVENT

Following event like methods are designed for process/worker communication, so DO NOT abuse them

on(event: string, handler: (...args: any[]) => void): void

  • error

error event will be emitted while the process/worker error occurred

  • property-changed

property changed event will be emitted while the in process/worker class property changed

once(event: string, handler: (...args: any[]) => void): void

emit(event: string, ...args: any[]): void

off(event: string): void

Contributing

Just feel free to post issues or suggestions, this package is under MIT lisence