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

golems

v0.0.5

Published

Golems is a simple cross-platform Haxe worker system.

Downloads

1

Readme

Golems

Golems is a simple cross-platform Haxe worker system. Its goal is to make it easier for developers to benefit from Haxe's targets' concurrency features. Golems currently supports the Flash, JS, NekoVM and C++ targets, and perhaps others.

What's inside

The Golems library currently includes two solutions:

  • A simple cross-platform "worker" implementation
    • To kick tasks to a separate thread, wrap them in a BasicWorker and invoke them through a BasicBoss (usually a QuickBoss).
  • A cross-platform macro for embedding workers into the main executable
    • Most workers are initialized from separate executables. Golem::rise lets you compile and embed workers inline into one executable.

Technically, these two solutions can be used independent of one another. They may in the future be replaced or supplemented with better solutions to the same problems. Additionally, a helper class called TempAgency can be used to spin up and manage multiple threads that are performing the same operation on different data simultaneously.

A simple use case

BasicWorkers are simple objects containing a process function of type TInput->Null<TOutput>. They run synchronously; they do not return until they're done processing their input. Their output is sent to the main thread, and if an error occurs, that is sent to the main thread as well.

BasicBosses are the objects that maintain communication between the main thread and worker thread. Extending BasicBoss is possible, but nine times out of ten, its subclass QuickBoss will be sufficient for our needs.

Say you're writing an application that includes a utility to crunch data. One day you find that when the utility is given an especially heavy task, your application becomes unresponsive.

Rats! Well, here's something you can do.

First, create a small hxml project adjacent to your application's. This will be the workers' project. Inside, write a standard compile target description for each platform your application runs on– but prepend each one with the special comment ###GOLEM###:

##GOLEM##
-main com.whoeveryouare.app.workers.DataCruncher
-js golems/DataCruncher.js
-cp src
-lib golems

You'll want to create a class called DataCruncher, then, in the package mentioned above:

package com.whoeveryouare.app.workers;

import com.whoeveryouare.app.utils.SlowUtility;
import net.rezmason.utils.workers.BasicWorker;

class TestWorker extends BasicWorker<YourInputType, YourOutputType> {
    override function process(input) return SlowUtility.crunchData(input);
}

There we go! We just wrote a worker. This will compile separately from the rest of your project. No need for a main function; Golems shove their own in. You may use a constructor, if you'd like.

To use this worker, we'll shoehorn it into your existing code:

// grab the worker once
var worker = Golem.rise('datacruncher.hxml');

// invoke the boss when you know there's work to be done
var boss = new QuickBoss(worker, onDataCrunched, onDataCrunchError);
boss.start();

// send the worker its work when you have it
boss.send(someInput);

// handle the worker's output
function onDataCrunched(crunchedData:YourOutputType) { ... }

// optionally handle the worker's errors
function onDataCrunchError(error:Dynamic) { ... }

// finally, when you're done with the worker, well...
boss.die();
boss = null;

When you build your application, Golem::rise will run the Haxe compiler against the worker project, grab the output, and assign it to the worker variable. When your code runs, the boss will create the worker, start it, communicate with it, and terminate it. Voilà! Your data will be crunched outside your application's event loop, its responsiveness will improve, and you'll be able to shift your focus to the other bugs in your code.

What's not in Golems

I suspect the current version of the library will support eighty to ninety percent of what people want from a Haxe concurrency library. Bitcoin miners, bioinformatics lab technicians and AI researchers might wish that Golems had a richer feature set, such as more nuanced communications between threads or shared memory.

I'd recommend another library, IF THERE WAS ONE.

Maybe Golems will become that library. I'm not only open to contributions, I would in fact like someone else to maintain it, preferably someone who uses concurrency more frequently than I do, or who is more actively involved in the Haxe community than I am.

I should probably mention

If you're using Golems in an Adobe AIR project, your workers will be created with application sandbox privileges.

License

Golems is licensed under the LGPLv3. It's a real page-turner.