Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace 'process.nextTick' with 'setTimeout'

  • Loading branch information...
commit 4c0152c4f310016b8473ab272511b9063ed0db23 1 parent 01f2a32
@nakamura-to authored
View
2  examples/countdown.js
@@ -2,7 +2,7 @@ var gate = require('../index');
var fs = require('fs');
var files = ['file1', 'file2'];
-var g = gate.create(files.length);
+var g = gate.create({count: files.length});
g.await(function (err, results) {
if (err) throw err;
console.log(results[0]); // { name: 'file1', data: 'FILE1' }
View
6 examples/error_check_skipping.js
@@ -1,9 +1,9 @@
var gate = require('../index');
var fs = require('fs');
-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));
+var g = gate.create({failFast: false});
+fs.readFile('non-existent1', 'utf8', g.latch({err: 0, data: 1}));
+fs.readFile('no n-existent2', 'utf8', g.latch({err: 0, data: 1}));
g.await(function (err, results) {
if (results[0].err) {
View
44 test/gate_test.js
@@ -5,8 +5,8 @@ describe('latch', function() {
it('should latch with index', function (done) {
var g = gate.create();
- process.nextTick(g.latch({val: 'a'}));
- process.nextTick(g.latch({val: 'b'}));
+ setTimeout(g.latch({val: 'a'}), 0);
+ setTimeout(g.latch({val: 'b'}), 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual({val: 'a'}, results[0]);
@@ -17,8 +17,8 @@ describe('latch', function() {
it('should latch with name', function (done) {
var g = gate.create();
- process.nextTick(g.latch('hoge', {val: 'a'}));
- process.nextTick(g.latch('foo', {val: 'b'}));
+ setTimeout(g.latch('hoge', {val: 'a'}), 0);
+ setTimeout(g.latch('foo', {val: 'b'}), 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual({val: 'a'}, results.hoge);
@@ -29,8 +29,8 @@ describe('latch', function() {
it('should latch with index and name', function (done) {
var g = gate.create();
- process.nextTick(g.latch('hoge', {val: 'a'}));
- process.nextTick(g.latch({val: 'b'}));
+ setTimeout(g.latch('hoge', {val: 'a'}), 0);
+ setTimeout(g.latch({val: 'b'}), 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual({val: 'a'}, results.hoge);
@@ -41,8 +41,8 @@ describe('latch', function() {
it('should await async calls', function (done) {
var g = gate.create();
- process.nextTick(g.latch({val: 'a'}));
- process.nextTick(g.latch({val: 'b'}));
+ setTimeout(g.latch({val: 'a'}), 0);
+ setTimeout(g.latch({val: 'b'}), 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual([{val: 'a'}, {val: 'b'}], results);
@@ -57,13 +57,13 @@ describe('latch', function() {
assert.deepEqual([{val: 'a'}, {val: 'b'}, {val: 'c'}], results);
done();
});
- process.nextTick(g.latch({val: 'a'}));
+ setTimeout(g.latch({val: 'a'}), 0);
assert.strictEqual(2, g.count);
- process.nextTick(g.latch({val: 'b'}));
+ setTimeout(g.latch({val: 'b'}), 0);
assert.strictEqual(1, g.count);
- process.nextTick(g.latch({val: 'c'}));
+ setTimeout(g.latch({val: 'c'}), 0);
assert.strictEqual(0, g.count);
- process.nextTick(g.latch({val: 'd'}));
+ setTimeout(g.latch({val: 'd'}), 0);
assert.strictEqual(0, g.count);
});
@@ -98,9 +98,9 @@ describe('latch', function() {
it('should handle non-error object', function (done) {
var g = gate.create();
var callback = g.latch();
- process.nextTick(function () {
+ setTimeout(function () {
callback('ERROR');
- });
+ }, 0);
g.await(function (err) {
if (err) throw err;
done();
@@ -110,9 +110,9 @@ describe('latch', function() {
it('should handle error object', function (done) {
var g = gate.create();
var callback = g.latch();
- process.nextTick(function () {
+ setTimeout(function () {
callback(new Error('ERROR'));
- });
+ }, 0);
g.await(function (err) {
assert.strictEqual('ERROR', err.message);
assert(err.gate_location);
@@ -123,9 +123,9 @@ describe('latch', function() {
it('should skip error check', function (done) {
var g = gate.create({failFast: false});
var callback = g.latch(0);
- process.nextTick(function () {
+ setTimeout(function () {
callback(new Error('ERROR'));
- });
+ }, 0);
g.await(function (err, results) {
assert.ok('ERROR', results[0].message);
done();
@@ -135,9 +135,9 @@ describe('latch', function() {
it('should map values', function (done) {
var g = gate.create();
var callback = g.latch({name: 'aaa', age: g.val(20), arg1: 1, arg2: 2});
- process.nextTick(function () {
+ setTimeout(function () {
callback(0, 'bbb', 100);
- });
+ }, 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual([{name: 'aaa', age: 20, arg1: 'bbb', arg2: 100}], results);
@@ -148,9 +148,9 @@ describe('latch', function() {
it('should map all values', function (done) {
var g = gate.create();
var callback = g.latch();
- process.nextTick(function () {
+ setTimeout(function () {
callback(null, 'bbb', 100);
- });
+ }, 0);
g.await(function (err, results) {
if (err) throw err;
assert.deepEqual([[null, 'bbb', 100]], results);
Please sign in to comment.
Something went wrong with that request. Please try again.