work.flow

0.0.0 • Public • Published

work.flow - The asynchronous workflow library for Node

Gemnasium

build status

coverage

coverage

npm version

Chat

work.flow is an asynchronous workflow library for Node.

The current version is 0.0.0 and is still going through documentation and testing before development starts, Unless you are contributing, you should probably not be using this.

The purpose of work.flow is to provide a means of creating individual pieces of code that can be used to quickly create applications or data processing pipelines.

TLDR;

print-line.js

 
module.exports = work.flow.task.definition({
    uri: 'incredi.co/games/worlds-fastest-game/print-line',
    properties: {
        message: {
            type: String,
            value: ''
        }
    },
    task: function(options, complete) {
        var message = options.properties.message;
        console.log(message);
        return complete(null, message);
    }
});
 

ask-name.js

 
var util = require('util');
var work = require('work.flow');
var readline = require('readline');
 
var io = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
 
module.exports = work.flow.task.definition({
    uri: 'incredi.co/games/worlds-fastest-game/ask-name',
    properties: {
        for: {
            type: String,
            value: 'Buddy'
        },
        prompt: {
            type: String,
            value: 'Hey %s, What is your name?',
            readOnly: true
        }
    },
    task: function(options, complete) {
        var prompt = util.format(options.properties.prompt, options.properties.for);
        return io.question(prompt, function(name) {
            return complete(null, name);
        });
    }
});
 

ask-for-player-names.js

 
require('./ask-name');
 
module.exports = work.flow.path.definition({
    uri: 'incredi.co/games/worlds-fastest-game/paths/ask-for-player-names',
    start: [{
        name: 'player-one',
        uri: 'incredi.co/games/worlds-fastest-game/ask-name',
        properties: {
            for: 'Player 1'
        }
    }, {
        name: 'player-two',
        uri: 'incredi.co/games/worlds-fastest-game/ask-name',
        properties: {
            for: 'Player 2'
        }
    }],
    timeout: 6000,
    error: [{
        uri: 'work.flow/task/restart'
    }]
});
 

workflow.js

 
require('./print-line');
require('./ask-for-player-names');
 
module.exports = work.flow.definition({
    name: 'worlds-fastest-game',
    uri: 'incredi.co/games/worlds-fastest-game',
    start: [{
        name: 'ask-names',
        uri: 'incredi.co/games/worlds-fastest-game/paths/ask-for-player-names'
    }, {
        name: 'determine-winner',
        uri: 'work.flow/task/if-then-else',
        properties: {
            if: {
                value: function(options, callback) {
          //@info return a random number between 1 & 2.
                    return callback(null, Math.round(Math.random() * (2 - 1) + 1));
                },
                equals: 1,
                then: [{
                    name: 'player-one-wins',
                    uri: 'incredi.co/games/worlds-fastest-game/print-line',
                    properties: {
                        message: '{ask-names.player-one} WINS!!!!'
                    }
                }],
                else: [{
                    name: 'player-two-wins',
                    uri: 'incredi.co/games/worlds-fastest-game/print-line',
                    properties: {
                        message: '{ask-names.player-two} WINS!!!!'
                    }
                }]
            }
        }
    }, {
        uri: 'work.flow/workflow/restart'
    }],
    timeout: 6000,
    error: [{
        uri: 'work.flow/workflow/restart'
    }]
});
 

index.js

 
var workflow = require('./workflow');
//@info lets run the worlds fastest game
workflow.run(function(err, context){
  //@info The worlds fastest game is also the longest
  //      If you take a close look at the work flow
  //      It will never actually end...
  console.log('MUAHAHAHAHAHAHAHAH');
});
 
 

Installation

$ npm install work.flow --save

Development Scripts

Before running any development scripts, be sure to first install the dev modules.

$ npm install work.flow --save --dev

Build Documentation

Outputs code documentation files to the ./doc/api folder.

$ npm run doc

Static Analysis

Outputs static analysis files to the ./doc/analysis folder.

$ npm run analyze

Test + Coverage

Outputs code coverage files to the ./doc/coverage folder.

$ npm run test

Package Sidebar

Install

npm i work.flow

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • defstream