railway-service

0.0.1-beta • Public • Published

Railway Service

Implementation of railway oriented programming in javascript. Long story short what it does is executes all defined steps if there is no error. Otherwise it will stop executing steps right after failed step.

Usage

  • Create a service (for example RocketService)
const rocketService = new RailwayService();
  • Add a step
  • Each step must return either {error: ...} or {params: ...}
rocketService.addStep((p) => {
    if (p.buttonPushed) {
        return { params: { fuel: 100 } };
    }
    return { error: "push the button" };
});
  • Steps get params from previous step
rocketService.addStep((p) => {
    if (p.fuel === 100) {
        return { params: "init lighter" };
    }
    return { error: "not enough fuel" };
});
  • Finally run the service
const res = rocketService.run({buttonPushed: true});
  • It will return boolean succeeded property or error if occurred

For more information about Railway Oriented Programming please refer to http://www.slideshare.net/ScottWlaschin/railway-oriented-programming

Readme

Keywords

Package Sidebar

Install

npm i railway-service

Weekly Downloads

3

Version

0.0.1-beta

License

none

Last publish

Collaborators

  • imorfie