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

gjs-multiprocess

v0.0.1-alpha.4

Published

Multiprocessing for GJS scripts.

Downloads

91

Readme

gjs-multiprocess

A simple API for running child-processes and comunicating with them via DBus.

Usage

// worker.js

export function calculatePi(digits) {
  // some calculations
  return result;
}
// main.js

const server = await startServer("org.my.app");

const client = await server.createClient("./worker.js");
// note: path to the worker must be relative to the current working directory or absolute

const pi = await client.invoke.calculatePi(1000);

console.log(pi);

client.terminate();
server.close();

Exposing methods to the client

Main process can expose methods to the client by passing an object to the createClient function.

// main.js

const mainProcessApi = {
  // Pass a log message to the Logger class in the main process
  log: (message) => Logger.info(message),
};

const client = await server.createClient("./worker.js", mainProcessApi);
// worker.js

export function doWork(message) {
  try {
    // ...
  } catch (error) {
    Subprocess.invoke.log(error.message);
  }
}

TypeScript

If you are using TypeScript you will want to have the client and Subprocess fully typed. That cannot be done automatically, since it's impossible atm to infer type definitions from a filepath. But you can fairly easily provide those typings manually:

Worker Typings

// worker.ts

export function calculatePi(digits: number): string {
  // some calculations
  return result;
}

export function reverse(str: string): string {
  return str.split("").reverse().join("");
}
import type * as Worker from "./worker";

const server = await startServer("org.my.app");

const client = await server.createClient<typeof Worker>("./worker.ts");

Main Process Typings

In case of the main process exported methods, those must be declared on a interface in the global scope called MainProcessApi.

// main.ts

const mainProcessApi = {
  // Pass a log message to the Logger class in the main process
  log: (message: string) => Logger.info(message),
};

const client = await server.createClient("./worker.ts", mainProcessApi);
// worker.ts

declare global {
  // Methods in this interface should match the methods provided by the main process
  interface MainProcessApi {
    log(message: string): void;
  }
}

Subprocess.invoke.log("Hello from the worker!");