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

@trytrench/flow

v0.0.9

Published

Typescript DAG Execution

Downloads

4

Readme

Flow: TypeScript Promise DAG Execution

Flow enables you to define type-safe Promise Directed Acyclic Graphs (DAGs) and execute them in the most efficient order.

Installation

npm i @trytrench/flow

Using Flow

Here is how you can utilize Flow in your code:

Step 1: Initialize Node Builder

First, initialize a Node Builder with a specific NodeInput type:

import { initNodeBuilder } from "@trytrench/flow";

type NodeInput = {
  timestamp: Date;
};

const nodeBuilder = initNodeBuilder.input<NodeInput>().create();

Step 2: Create Nodes

Next, create the nodes. Here we create temperatureNode and windSpeedNode that fetch data asynchronously from APIs. We then create windChillNode that depends on temperatureNode and windSpeedNode, and calculates the wind chill factor:

const temperatureNode = nodeBuilder
  .resolver(async ({ input }) => {
    const temperature = await fetchTemperatureFromApi(input.timestamp);
    return temperature;
  });

const windSpeedNode = nodeBuilder
  .resolver(async ({ input }) => {
    const windSpeed = await fetchWindSpeedFromApi(input.timestamp);
    return windSpeed;
  });

const windChillNode = nodeBuilder
  .depend({
    temperature: temperatureNode,
    windSpeed: windSpeedNode,
  })
  .resolver(({ deps }) => {
    const { temperature, windSpeed } = deps;
    const windChillFactor = calculateWindChill(temperature, windSpeed);
    return windChillFactor;
  });

Step 3: Run Node

Finally, run the nodes. In this case, we're executing windChillNode and logging the returned wind chill factor:

windChillNode
  .run({
    timestamp: new Date(),
  })
  .then((windChillFactor) => {
    console.log(`The wind chill factor is: ${windChillFactor}`);
  })
  .catch((err) => {
    console.error(err);
  });