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

hyber

v0.2.0

Published

make node.js get power of multi-process.

Downloads

1

Readme

hyber CircleCI

make node.js get power of multi-process.

Experimental

Be cautious if you want to use it in your real projects.

Introduction

As we all know, JavaScript, running in a single main process environment, can deal some specific jobs with another process. Unfortunately we can not create any child process directly.

Thank to the child_process module provided by Node.js, we are able to create child processes by shell commands. The most special one, child_process.fork, can be used to create child processes by JavaScript files.

The trouble is we have to leave the function of the child process an individual file and use the message mechanism to receive values from the child process. That's not really cool.

Image what if we create a child process as easy as creating a Promise object, how fantastic it will be.

Principle

The hyber function will add some details, tranform your function into temporary file and call it.

Suppose you give a function like this

function add(a, b) {
  return a + b
}

Then it will be transformed to

`(function add(a, b) {
    return a + b
})(arg1, arg2)
`

Once you give the arguments, they will be filled into the string like

;`(function add(a, b) {
    return a + b
})(10, 20)
`

Send message to the main process

`const value = (function add(a, b) {
    return a + b)
})(10, 20)
process.send(value)
`

Eventually, fork the file and handle the message by Promise.

That's it.

Usage

Import

import hyber from 'hyber'

Install at first

npm install hyber
# or
yarn add hyber

Without Argument

const func = () => 10
const asyncFunc = hyber(func)

// 10
const result = await asyncFunc()

With Arguments

hyber generates a new function, you should pass the arguments into the new one.

const func = a => a + 10
const asyncFunc = hyber(func)

// 30
const result = await asyncFunc(20)

NOTICE

Since the new function generated by hyberruns in a completely different process, it can not capture any variables in the current process. You have to pass all variables as arguments.

Use it only if you want to do tons of calculations without blocking the main process.