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

callflow

v0.5.4

Published

Control your asynchronous code with explicit flows! Created mainly for simplifying code within SwarmESB projects but can be used outside SwarmESB ecosystem

Downloads

10

Readme

#callflow: control your asynchronous code with explicit flows

This library purpose a concept of flow based on explicit continuations.

The idea of the library is to represent asynchronous code (or even synchronous but complex code) as a set pf phases in a workflow. The code using asynchron avoids the infamous pyramid of callbacks by structuring code in a list of functions (phases) that also control the transitions between phases using "next" and "continue" primitives. Transitions between phases can get triggered by directly calls to other phases, by asynchronous calls (next) and by a continuations given in place of a asynchronous callback. The flows have also the concept of "join" that are dormant phases that get called only when the whole list of declared phases got executed.

Syntax & primitives: The syntax of a flow is a JSON with values as functions phases and join phases

The flow can be seen as a set of phases and the computation will pass through each one (synchronously and asynchronously) Each phase has a name. Phases can be function phases or join phases. If a phase is a function phase, the field value in the JSON is a function. If a phase is a join phase, the value of the field is an object with a member "join" containing a list with the names of the phases that are waited until the join phase get called (see examples). Two special functions, called flow primitives, are available in all

Flow variables

When a flow is created, a Java Script object is created. This object beside containing as members all the functions of the flow, the "next" and "continue" functions, it can also contain arbitrary variables.

Basic example:

  var flow = require("callflow");
  var f = flow.createFlow("Flow example", {
        begin:function(a1,a2){
            //.. code
            this.variable = false;
            this.step();
        },
        step:function(a){
            //this.variable is set in begin
            //.. code     
                    
        }
    });
    f();

Example with a join and use of continue:

  var f = flow.createFlow("Flow example", {
        begin:function(a1,a2){
            //..
            this.step(true);
            this.next("step", "Comment explaining why was this function called", true); // quite similar with this.step(true) but step wll be executed at nextTick   
            
            asyncFunction(this.continue("callback","Called later by asyncFunction");
        },
        step:function(a){
            //a will be true in both cases
            //..code
            
        }
        callback:function(err,res){
                        //..
            
        }
        end:{
            join:"step,callback", //waits 2 calls of step and one of callback
            code:function(){
            //..called     
        }            
    });
    var flow = f();
    f.status(); // see the flow status

Integration with the "whys" module (https://github.com/salboaie/whys)

From the beginning, we created flows with the idea to have automated integration with the "whys" module. Each phase transitions is automatically logged with a "why" call explaining the transition.
Beside automated integration, why calls can be performed at will anywhere and the why system will compact the tracking logs for each call. "next" and "continue" functions have the second argument an string that is automatically passed to the why.

  var flow = require("callflow");
       var f = flow.createFlow("Flow example", {
             begin:function(a1,a2){
                 //.. code
                 this.step.why("explanantions...")();                     
             }.why("Additional info"),
             step:function(a){
                 //.. code                
             }.why("Additional info")
         });
         f.why("Additional info")();