ticks-tracer
v1.3.0
Published
takes snapshots for an object across event loop ticks
Downloads
24
Maintainers
Readme
Ticks Tracer
Takes snapshots for an object across event loop ticks.
Hint
Good for testing flow control packages like flowa
, async
, q
, etc.
Table of Contents
Installation
npm install --save ticks-tracer
Usage
Take snapshot on every check
phase of the event loop (using setImmediate
internally).
var TicksTracer = require('ticks-tracer');
// A flow control package
var Flowa = require('flowa');
// The object to trace
var context = {};
// A dummy flow
var flow = new Flowa({
type: 'serial',
task1: generateDummyTask(1),
task2: generateDummyTask(2),
group1: {
type: 'parallel',
task3: generateDummyTask(3),
task4: generateDummyTask(4)
},
task5: generateDummyTask(5)
});
// Start tracing
var ticksTracer = new TicksTracer(context);
// Execute the tasks
flow.run(context).then(function(result) {
// Get the taken snapshots
console.log(ticksTracer.getSnapshots());
console.log(ticksTracer.getSnapshotsDiffs());
// Stop the tracing
ticksTracer.stop();
});
// Don't worry about this
function generateDummyTask(id) {
return function(context, callback) {
context['task' + id] = true;
setImmediate(callback);
};
}
The output is:
[
{},
{ task1: true },
{ task1: true, task2: true },
{ task1: true, task2: true, task3: true, task4: true },
{ task1: true, task2: true, task3: true, task4: true, task5: true }
]
API
TicksTracer(tracedObject)
To create a TicksTracer object and start tracing.
| Param | Type | Description | |--------------|---------------------|---------------------------------| | tracedObject | Object | The object to take snapshots of |
stop()
Stop tracing.
getTicksCount() ⇒ Number
Get the current tick number.
Returns: Number
getSnapshotAt(tick) ⇒ Object
Get a taken snapshot by a tick number.
| Param | Type | Description | |-------|---------------------|---------------------------------| | tick | Number | The tick number |
Returns: Object
getSnapshots() ⇒ Array
Get all taken snapshots indexed by ticks numbers.
Returns: Array
getSnapshotsDiffs() ⇒ Array
Get a list of snapshots that represent only the diffs
Returns: Array
License
This project is under the MIT license.