quick async example in readme
to get started would be useful. Can you pass a callback to Suite#add()'s function or how does the async support work? The readme example has async: true but the code isn't async
Ok will do. The async option is executing the tests async to give the UI a chance to update. What you want is the defer option to use the deferred object and its deferred.resolve(). See docs/#Benchmark.
ah! I see cool
The async option is executing the tests async to give the UI a chance to update.
@jdalton does it mean that the async: true/false can be ignored if used in node? because there is no UI in node.
does it mean that the async: true/false can be ignored if used in node? because there is no UI in node.
It may still lock up the terminal while it crunches through them so it's up to you.
ok, thank you!
So when you specify 'defer': true as option the test function you provide gets a deferred object with a resolve function? (This wasn't really obvious for me looking through the docs).
So the following would work?
// Using deferred test
var bench = new Benchmark('foo', function(deferred) {
// call resolve() when the deferred test is finished
deferred.resolve();
}, {
// a flag to indicate the benchmark is deferred
'defer': true,
});
// Using deferred test
var bench = new Benchmark('foo', {
// a flag to indicate the benchmark is deferred
'defer': true,
// benchmark test function
'fn': function(deferred) {
// call resolve() when the deferred test is finished
deferred.resolve();
}
});
I would also like a deferred example in the readme, maybe something like:
...
// add deferred test
suite.add('Deferred test', function(deferred) {
// call resolve() when the deferred test is finished
deferred.resolve();
}, {'defer': true})
...