Skip to content

Commit feb1faa

Browse files
committed
Merge pull request #824 from fintura/async
Remove async dependency
2 parents c947e8f + 43e25e7 commit feb1faa

File tree

4 files changed

+24
-47
lines changed

4 files changed

+24
-47
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"jshint": "./node_modules/.bin/jshint *"
1717
},
1818
"devDependencies": {
19-
"async": "^1.3.0",
2019
"coveralls": "^2.11.2",
2120
"hiredis": "^0.4.1",
2221
"jshint": "^2.8.0",

test/commands/flushdb.spec.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var async = require('async');
43
var assert = require('assert');
54
var config = require("../lib/config");
65
var helper = require('../helper');
@@ -57,29 +56,16 @@ describe("The 'flushdb' method", function () {
5756
});
5857

5958
describe("when there is data in Redis", function () {
60-
var oldSize;
6159

6260
beforeEach(function (done) {
63-
async.parallel([function (next) {
64-
client.mset(key, uuid.v4(), key2, uuid.v4(), function (err, res) {
65-
helper.isNotError()(err, res);
66-
next(err);
67-
});
68-
}, function (next) {
69-
client.dbsize([], function (err, res) {
70-
helper.isType.positiveNumber()(err, res);
71-
oldSize = res;
72-
next(err);
73-
});
74-
}], function (err) {
75-
if (err) {
76-
return done(err);
77-
}
78-
79-
client.FLUSHDB(function (err, res) {
80-
helper.isString("OK")(err, res);
81-
done(err);
82-
});
61+
var end = helper.callFuncAfter(function () {
62+
client.flushdb(helper.isString("OK", done));
63+
}, 2);
64+
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError(end));
65+
client.dbsize([], function (err, res) {
66+
helper.isType.positiveNumber()(err, res);
67+
assert.equal(res, 2, 'Two keys should have been inserted');
68+
end();
8369
});
8470
});
8571

test/helper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,14 @@ module.exports = {
116116
var mochaListener = process.listeners('uncaughtException').pop();
117117
process.removeListener('uncaughtException', mochaListener);
118118
return mochaListener;
119+
},
120+
callFuncAfter: function (func, max) {
121+
var i = 0;
122+
return function () {
123+
i++;
124+
if (i === max) {
125+
func();
126+
}
127+
};
119128
}
120129
};

test/node_redis.spec.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var async = require("async");
43
var assert = require("assert");
54
var config = require("./lib/config");
65
var helper = require('./helper');
@@ -122,31 +121,15 @@ describe("The node_redis client", function () {
122121
it("reconnects and can retrieve the pre-existing data", function (done) {
123122
client.on("reconnecting", function on_recon(params) {
124123
client.on("connect", function on_connect() {
125-
async.parallel([function (cb) {
126-
client.get("recon 1", function (err, res) {
127-
helper.isString("one")(err, res);
128-
cb();
129-
});
130-
}, function (cb) {
131-
client.get("recon 1", function (err, res) {
132-
helper.isString("one")(err, res);
133-
cb();
134-
});
135-
}, function (cb) {
136-
client.get("recon 2", function (err, res) {
137-
helper.isString("two")(err, res);
138-
cb();
139-
});
140-
}, function (cb) {
141-
client.get("recon 2", function (err, res) {
142-
helper.isString("two")(err, res);
143-
cb();
144-
});
145-
}], function (err, results) {
124+
var end = helper.callFuncAfter(function () {
146125
client.removeListener("connect", on_connect);
147126
client.removeListener("reconnecting", on_recon);
148-
done(err);
149-
});
127+
done();
128+
}, 4);
129+
client.get("recon 1", helper.isString("one", end));
130+
client.get("recon 1", helper.isString("one", end));
131+
client.get("recon 2", helper.isString("two", end));
132+
client.get("recon 2", helper.isString("two", end));
150133
});
151134
});
152135

0 commit comments

Comments
 (0)