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

@receptron/graphai_lite

v0.0.15

Published

GraphAI Lite

Downloads

3

Readme

GraphAI Lite

GraphAI Lite is a light-weight version of GraphAI, the declarative data-flow programming framework that makes it easy to develop complex applications utilizing multiple asynchronous calls and their concurrent executions.

GraphAI Lite consists of a set of small TypeScript libraries, allowing developers to leverage data-flow programming and eliminate the need to manage complex states involving asynchronous calls and concurrent executions.

Usage

While async/await has simplified calling asynchronous functions, everything is executed sequentially, even when the tasks are independent.

const ExecuteAtoF = async () => {
  const a = await FuncA();
  const b = await FuncB();
  const c = await FuncC();
  const d = await FuncD(a, b);
  const e = await FuncE(b, c);
  return FuncF(d, e);
};

To execute independent asynchronous tasks concurrently, you need to use Promise.all. However, fully optimizing this can lead to hard-to-maintain code.

For example, the code below is slightly optimized but not fully optimized (FuncD needs to wait until FuncC is done even though there is no dependency, and FuncE needs to wait for FuncA).

const ExecuteAtoF = async () => {
  const [a, b, c] = await Promise.all([FuncA(), FuncB(), FuncC()]);
  const [d, e] = await Promise.all([FuncD(a, b), FuncE(b, c)]);
  return FuncF(d, e);
};

The computed function of GraphAI Lite is a thin wrapper around Promise.all, enabling data-flow style programming. You just need to specify the dependencies of various tasks (nodes) and let the system figure out the appropriate execution order.

import { computed } from '@receptron/graphai_lite';

const ExecuteAtoF = async () => {
  const nodeA = FuncA();
  const nodeB = FuncB();
  const nodeC = FuncC();
  const nodeD = computed([nodeA, nodeB], FuncD);
  const nodeE = computed([nodeB, nodeC], FuncE);
  const nodeF = computed([nodeD, nodeE], FuncF);
  return nodeF;
};

Below is the data-flow diagram represented by the code above (the graph is visible only on Github).

flowchart LR
 nodeA --> nodeD
 nodeB --> nodeD
 nodeB --> nodeE
 nodeC --> nodeE
 nodeD --> nodeF
 nodeE --> nodeF

Conductor

The Conductor class of GraphAI Lite allows developers to log the executions of those asynchronous tasks.

import { Conductor } from '@receptron/graphai_lite';

const ExecuteAtoF = async (conductor: Conductor) => {
  const nodeA = conductor.computed([], FuncA, { name: "nodeA" });
  const nodeB = conductor.computed([], FuncB, { name: "nodeB" });
  const nodeC = conductor.computed([], FuncC, { name: "nodeC" });
  const nodeD = conductor.computed([nodeA, nodeB], FuncD, { name: "nodeD" });
  const nodeE = conductor.computed([nodeB, nodeC], FuncE, { name: "nodeE" });
  const nodeF = conductor.computed([nodeD, nodeE], FuncF, { name: "nodeF" });
  conductor.result = {
    f: await nodeF
  };
};

const main = async () => {
  const conductor = new Conductor({ verbose:true, recordInputs: true, recordOutput: true });
  await ExecuteAtoF(conductor);
  console.log(conductor.logs);
  console.log(conductor.result);
}