mo-sequencer

0.0.1 • Public • Published

(˘▾˘) mo-sequencer

Comparison to async style

Comparison to async

How it works

Function inside sequencer parsed as a string. All function calls prefixed with ~~ and ~! are executed first, and substituted by resulting value. Prefix types are:

  • ~~ for traditional callback(err, result)
  • ~! for promises

Copy-paste template

Please, copy comment when use sequencer, because ~~ and ~! - it's new "coordinate system" which may confuse your colleagues.

    var sequencer = require('mo-sequencer');

    // (~˘▾˘)~ mo-sequencer: ~~ is call of async function; ~! is call of promise
    sequencer((__o, __0) => { eval(__o)}, () => {
        
    });

Install

npm i mo-sequencer --save

or

bower i mo-sequencer --save

Usage

    var someObject, someValue;
    // (~˘▾˘)~ mo-sequencer: ~~ is call of async function; ~! is call of promise
    sequencer((__o, __0) => { eval(__o)}, () => {
        someValue = ~~asyncMultiplier(1);
        someObject = {
            value1: ~~asyncMultiplier(10),
            value2: ~~asyncMultiplier(5)
        };
        console.log(someValue, someObject);
    });
    
    function asyncMultiplier(number, callback) {
        setTimeout(function() {
            callback(null, number * 2);
        }, 1);
    }

Explanation

Let's see explanation of what happens on example, which we could have in real environment:

Explanation

Test on your machine

Download repo and check if example.js looks cool in your favorite IDE.

git clone https://github.com/mojects/mo-sequencer.git
npm i
node example.js

Current implementation - is prototype

Examples above work well on node and browser. Though there are list of limitations (see how to facilitate for their elimination) In current prototype following is not supported:

  • Not supported: declarations of var. (need to declare outside of sequencer, like in Usage example)
  • Not supported: sub-functions in body of sequencer
  • Not supported: async call inside of another async call (as argument)
  • Not supported: if-conditions/switches/loops

Contribution

As you can see - prototype has pretty limited abilities. Though it already simplifies async code a lot and looks like a great potential!

Do not hesitate to post your random thoughts in chat and contribute.

Join the chat at https://gitter.im/mojects/mo-sequencer

Maybe, here together with you we will build future of async programming! :) Like this dude:

Future dude

Readme

Keywords

none

Package Sidebar

Install

npm i mo-sequencer

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • garmoshka-mo