Permalink
Browse files

Rename from `callbackLocation` to `gate_location`. Update examples.

  • Loading branch information...
1 parent a8b41c9 commit e8fe5d9c6c99938dbc2038c089902a6f0f81b1a7 @nakamura-to committed Jun 14, 2012
View
@@ -2,15 +2,15 @@ var gate = require('../index');
var fs = require('fs');
var files = ['file1', 'file2'];
-var latch = gate.latch(files.length);
-latch.await(function (err, results) {
+var g = gate.create(files.length);
+g.await(function (err, results) {
if (err) throw err;
console.log(results[0]); // { name: 'file1', data: 'FILE1' }
console.log(results[1]); // { name: 'file2', data: 'FILE2' }
});
process.nextTick(function () {
files.forEach(function (file) {
- fs.readFile(file, 'utf8', latch({name: file, data: 1}));
+ fs.readFile(file, 'utf8', g.latch({name: file, data: 1}));
});
});
@@ -1,11 +1,11 @@
var gate = require('../index');
var fs = require('fs');
-var latch = gate.latch();
-fs.readFile('non-existent1', 'utf8', latch({err: 0, data: 1}, true));
-fs.readFile('non-existent2', 'utf8', latch({err: 0, data: 1}, true));
+var g = gate.create();
+fs.readFile('non-existent1', 'utf8', g.latch({err: 0, data: 1}, true));
+fs.readFile('no n-existent2', 'utf8', g.latch({err: 0, data: 1}, true));
-latch.await(function (err, results) {
+g.await(function (err, results) {
results.forEach(function (result) {
if (result.err) {
console.log(result.err);
View
@@ -1,14 +1,14 @@
var gate = require('../index');
var fs = require('fs');
-var latch = gate.latch();
-fs.readFile('file1', 'utf8', latch({name: 'file1', data: 1}));
-fs.readFile('non-existent', 'utf8', latch({name: 'non-existent', data: 1}));
+var g = gate.create();
+fs.readFile('file1', 'utf8', g.latch({name: 'file1', data: 1}));
+fs.readFile('non-existent', 'utf8', g.latch({name: 'non-existent', data: 1}));
-latch.await(function (err, results) {
+g.await(function (err, results) {
if (err) {
- console.log(err + ', callbackLocation: ' + err.callbackLocation);
+ console.log(err + ', gate_location: ' + err.gate_location);
} else {
console.log(results);
}
-});
+});
View
@@ -1,12 +1,12 @@
var gate = require('../index');
var fs = require('fs');
-var latch = gate.latch();
+var g = gate.create();
['file1', 'file2'].forEach(function (file) {
- fs.readFile(file, 'utf8', latch({name: file, data: 1}));
+ fs.readFile(file, 'utf8', g.latch({name: file, data: 1}));
});
-latch.await(function (err, results) {
+g.await(function (err, results) {
if (err) throw err;
console.log(results[0]); // { name: 'file1', data: 'FILE1' }
console.log(results[1]); // { name: 'file2', data: 'FILE2' }
View
@@ -2,18 +2,18 @@ var gate = require('../index');
var fs = require('fs');
var exec = require('child_process').exec;
-var latch = gate.latch();
+var g = gate.create();
// single mapping: arguments[1] in the callback will be result
-fs.readFile('file1', 'utf8', latch(1));
+fs.readFile('file1', 'utf8', g.latch(1));
// multiple mapping: object including arguments[1] and argments[2] in the callback will be result
-exec('cat *.js bad_file | wc -l', latch({stdout: 1, stderr: 2}));
+exec('cat *.js bad_file | wc -l', g.latch({stdout: 1, stderr: 2}));
// all mapping: all arguments in the callback will be result
-fs.readFile('file2', 'utf8', latch());
+fs.readFile('file2', 'utf8', g.latch());
-latch.await(function (err, results) {
+g.await(function (err, results) {
if (err !== null) {
console.log('exec error: ' + err);
}
View
@@ -1,11 +1,11 @@
var gate = require('../index');
-var latch = gate.latch();
-setTimeout(latch({val: 'a'}), 30);
-setTimeout(latch({val: 'b'}), 20);
-setTimeout(latch({val: 'c'}), 10);
+var g = gate.create();
+setTimeout(g.latch({val: 'a'}), 30);
+setTimeout(g.latch({val: 'b'}), 20);
+setTimeout(g.latch({val: 'c'}), 10);
-latch.await(function (err, results) {
+g.await(function (err, results) {
if (err) throw err;
console.log(results);
});
View
@@ -1,11 +1,11 @@
var gate = require('../index');
var fs = require('fs');
-var latch = gate.latch();
-fs.readFile('file1', 'utf8', latch({name: 'file1', data: 1}));
-fs.readFile('file2', 'utf8', latch({name: 'file2', data: 1}));
+var g = gate.create();
+fs.readFile('file1', 'utf8', g.latch({name: 'file1', data: 1}));
+fs.readFile('file2', 'utf8', g.latch({name: 'file2', data: 1}));
-latch.await(function (err, results) {
+g.await(function (err, results) {
if (err) throw err;
console.log(results[0]); // { name: 'file1', data: 'FILE1' }
console.log(results[1]); // { name: 'file2', data: 'FILE2' }
View
@@ -12,12 +12,13 @@ function create(count) {
function Gate(count) {
this._async = new Async(count);
- Object.defineProperty(this, "count", {
- get: function () { return this._async.count; },
- enumerable: true
- });
}
+Object.defineProperty(Gate.prototype, "count", {
+ get: function count() { return this._async.count; },
+ enumerable: true
+});
+
Gate.prototype.latch = function latch(mapping, skipErrorCheck) {
return this._async.makeCallback(latch, mapping, skipErrorCheck);
};
@@ -70,8 +71,8 @@ Async.prototype.makeCallback = function makeCallback(caller, mapping, skipErrorC
var next = self.next;
self.pending--;
if (!self.canceled) {
- if (error && typeof error === 'object' && !('callbackLocation' in error)) {
- error.callbackLocation = location;
+ if (error && typeof error === 'object' && !('gate_location' in error)) {
+ error.gate_location = location;
}
if (error && !skipErrorCheck) {
self.canceled = true;
View
@@ -78,8 +78,8 @@ describe('latch', function() {
});
g.await(function (err) {
assert.strictEqual('ERROR', err.message);
- assert(err.callbackLocation);
- done();
+ assert(err.gate_location);
+ done();
});
});

0 comments on commit e8fe5d9

Please sign in to comment.