Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Added callback to library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Rademacher committed Feb 4, 2014
1 parent 82c4fb0 commit f12df1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/fs-report.js
Expand Up @@ -24,4 +24,7 @@ ab.run(fn, {
concurrency: 50,
requests: 200000,
filename: 'fs_exists.txt'
}, function(err, result) {
if (err) return console.error(err);
console.log(result);
});
6 changes: 5 additions & 1 deletion lib/ab.js
Expand Up @@ -22,7 +22,9 @@ var pkg = require('../package.json');
var HEAD = fs.readFileSync(path.join(__dirname, 'tpl', 'head.txt'), 'utf8');
var REPORT = fs.readFileSync(path.join(__dirname, 'tpl', 'report.txt'), 'utf8');

exports.run = function (fn, options) {
exports.run = function (fn, options, callback) {
if (callback) options.callback = callback;

return new Benchmark(fn, options).run();
};

Expand All @@ -33,6 +35,7 @@ function Benchmark(fn, options) {
this._name = options.name || '';
this.requests = options.requests || 100;
this.filename = options.filename || '';
this.callback = options.callback || null;
this._stageCount = Math.floor(this.requests / 10);
if (this._stageCount > 10000) {
this._stageCount = 10000;
Expand Down Expand Up @@ -217,6 +220,7 @@ Benchmark.prototype.run = function () {
} else {
console.log(report);
}
if (that.callback) that.callback(null);
that.emit('end');
});

Expand Down

0 comments on commit f12df1e

Please sign in to comment.