Takes snapshots for an object across event loop ticks.
Good for testing flow control packages like flowa
, async
, q
, etc.
npm install --save ticks-tracer
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 }
]
- TicksTracer(tracedObject)
To create a TicksTracer object and start tracing
- stop()
Stop tracing
- getTicksCount() ⇒
Number
Get the current tick number
- getSnapshotAt(tick) ⇒
Object
Get a taken snapshot by a tick number
- getSnapshots() ⇒
Array
Get all taken snapshots indexed by ticks numbers
- getSnapshotsDiffs() ⇒
Array
Get a list of snapshots that represent only the diffs
To create a TicksTracer object and start tracing.
Param | Type | Description |
---|---|---|
tracedObject | Object |
The object to take snapshots of |
Stop tracing.
Get the current tick number.
Returns: Number
Get a taken snapshot by a tick number.
Param | Type | Description |
---|---|---|
tick | Number |
The tick number |
Returns: Object
Get all taken snapshots indexed by ticks numbers.
Returns: Array
Get a list of snapshots that represent only the diffs
Returns: Array
This project is under the MIT license.