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

dataflowjs

v0.1.2

Published

A dataflow model for async programming.

Downloads

8

Readme

dataflowjs

An Javascript dataflow model for asynchronous programming. Using this model, one creates task graphs which are lazily evaluated on fire function. It is best explained by example.

Let's say you want to make multiple I/O calls to a DB or whatever and want all the results when all calls complete. Furthermore if the calls take too much time, timeout the whole set of calls and raise a warning. The following schematic depicts the dataflow graph.

parallel

What we can see from the graph is that 6 functions are called in parallel. Each task defines input ports and an activation expression. The evaluation of the expression determines if the task function is called or not. In the example the final function is only fired after the expression (p1 & p2 & p3 & p4 & p5) ^ p6 evaluates to True which means either all p1-5 are True or p6 which is the timeout is True.

The above is implemented as follows:

function mochcall(params, cb) {
	if (!params) {
		setTimeout(function() {
			cb("error", false);
		}, 0);
	} else {
		setTimeout(function() {
			cb(null, "hello from " + params.text);
		}, params.timeout);
	}
}

new dataflow.Dataflow()
	.create({
		name: "start"
	}, (data, t) => {
		t(['call1', 'call2', 'call3', 'call4', 'call5', 'timeout'], [])(null, data.value);
	})
	.create({
		name: "call1"
	}, (data, t) => {
		const params = {
				timeout: data.value,
				text: "call 1"
		};
		mochcall(params, t(["final:port1"], ["error"]));
	})
	.create({
		name: "call2"
	}, (data, t) => {
		const params = {
				timeout: data.value,
				text: "call 2"
		};
		mochcall(params, t(["final:port2"], ["error"]));
	})
	.create({
		name: "call3"
	}, (data, t) => {
		const params = {
				timeout: data.value,
				text: "call 3"
		};
		mochcall(params, t(["final:port3"], ["error"]));
	})
	.create({
		name: "call4"
	}, (data, t) => {
		const params = {
				timeout: data.value,
				text: "call 4"
		};
		mochcall(params, t(["final:port4"], ["error"]));
	})
	.create({
		name: "call5"
	}, (data, t) => {
		const params = {
				timeout: data.value,
				text: "call 5"
		};
		mochcall(params, t(["final:port5"], ["error"]));
	})
	.create({
		name: 'timeout'
	}, (data, t) => {
		setTimeout(() => {
			t(['final:timeout'], [])(null, "Timed out");
		}, 1000);
	})
	.create({
		name: "error"
	}, (err, t) => {
		console.error(err);
		throw new Error("some error");
	})
	.create({
		name: 'final',
		ports: ['port1', 'port2', 'port3', 'port4', 'port5', 'timeout'],
		expression: '(port1 & port2 & port3 & port4 & port5) ^ timeout'
	}, (data, t, state) => {
		console.log("final data: ", data);
	})
	.fire("start", 100);

create(options, function) registers a function, the options is a JSON object

{
  name: [task name: required],
  ports: [array with port names: optional],
  expression: [activation boolean port expression: optional]
}

Each registered function takes 2 parameters; a data parameter and a transfer callback. Since the tasks are asynchronous, results are returned through the transfer callback whereby the ports array indicate to which ports the data is being transferred. the transfer callback takes an array of success ports, an array of error ports, an error data object and a success data object t([array of success ports], [array of error ports])(errorObject, successObject). This pattern allows functions using the callback pattern to be used immediately just like the mochcall().

To start evaluating the graph, fire(taskName, data) is called on the dataflow object.