1.0.12 • Published 5 years ago

swint-pipe v1.0.12

Weekly downloads
110
License
MIT
Repository
github
Last release
5 years ago

swint-pipe

Greenkeeper badge Pipeline logic flow for Swint

Warning: This is not the final draft yet, so do not use this until its official version is launched

Installation

$ npm install --save swint-pipe

Edge

  • Atomic task(can be synchronous or asynchronous) defined by function.
  • Usage
var edge1 = Pipe.Edge(function(system, input, output) {
		db.fetch({
			// ...
		}, function(err, res) {
			output(/* ... */);
		});
	}); // asynchronous task

var edge2 = Pipe.Edge(function(system, input) {
		return input * 2;
	}); // synchronous task

edge1.input(1); // When edge is the input of whole system, the data flows to the `input` of the main function.
edge2.output(system, 'edge2'); // When edge is the output of whole system, the data flows to `system.out()`.

System

  • Defines the data flow using connect() and branch().
  • Handles the error using error().
  • Usage
var system = Pipe.System({
		foo: 'bar' // Global variable throughout the system
	});

system.connect(edge1, edge2); // `edge2` will wait for `edge1` to be finished
system.connect(edge2, [edge3, edge4]); // `edge3` and `edge4` will be fired right after `edge2` is finished
system.connect([edge3, edge4], edge5); // `edge5` will wait for both `edge3` and `edge4` to be finished
system.connect(edge5, edge6, function(before, after) {
	after(before * 2);
}); // can morph the pipelined data on connection
system.branch(edge6, [edge7, edge8, edge9], function(before, after) {
	switch(before.type) {
		case 'A':
			after(0, 'type A'); // `'type A'` will be passed to `edge7`(`0`th edge on the array), while `edge8` and `edge9` outputs `undefined`.
			break;
		case 'B':
			after(1, 'type B');
			break;
		case 'C':
			after(2, 'type C');
			break;
	}
}); // can branch between edges

system.end(function(output) {
	// ...
}); // executed when the whole system is ended

var edge1 = Pipe.Edge(function(system, input, output) {
		db.fetch({
			// ...
		}, function(err, res) {
			if(err) {
				system.throw('MyError', 'something happened'); // throws error to the system
				return;
			}
			// ...
		});
	});
system.error(function(type, err) {
	// handling the thrown error
});

system.start(); // actually starts the system
1.0.12

5 years ago

1.0.11

6 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago