1.0.0 • Published 10 years ago
cruks-lib-promise v1.0.0
Flow Inspector
Flow inspector provides promise-like Task objects and tools that allow aggregating them.
Examples
Task
var Task = require("cruks-lib-promise").Task,
task = new Task();
task.addListenerStart(function () {
console.log("Task is started.");
});
task.start();
task.addListenerStop(function () {
console.log("This is a not dead code.");
});
task.onceStopped(function () {
console.log("Task is already stopped.");
});
task.stop();
task.addListenerStop(function () {
console.log("This is a dead code.");
});
task.onceStopped(function () {
console.log("Task is already stopped for sure.");
});
Result:
Task is started.
This is not a dead code.
Task is already stopped.
Task is already stopped for sure.
Task Aggregator
var flowInspector = require("cruks-lib-promise"),
Task = flowInspector.Task,
TaskAggregator = flowInspector.TaskAggregator,
arr = [],
taskAggregator = new TaskAggregator(),
task1 = new Task(),
task2 = new Task(),
task3 = new Task();
taskAggregator.add(task1);
taskAggregator.add(task2);
taskAggregator.add(task3);
taskAggregator.onceEveryStop(function () {
console.log(arr);
});
task1.onceStarted(function () {
arr.push(1);
});
task2.onceStarted(function () {
arr.push(2);
});
task3.onceStarted(function () {
arr.push(3);
});
task2.start();
task2.stop();
task3.start();
task1.start();
task3.stop();
task1.stop();
Result:
[2, 3, 1]
Semantic Versioning
This repository follows Semantic Versioning convention.
1.0.0
10 years ago