Skip to content

Commit 8cd9cc4

Browse files
committed
Fixed the bug of reusing an old future.
1 parent 6f1946b commit 8cd9cc4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ blocking = function (obj, fun) {
88
fun = obj;
99
obj = undefined;
1010
}
11-
var future = new Future();
1211
var f = function () {
1312
if (_.isUndefined(obj)) {
1413
obj = this;
1514
}
1615
var args = _.toArray(arguments);
16+
var future = new Future();
1717
fun.apply(obj, args.concat(future.resolver()));
1818
return future.wait();
1919
};

tests.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ Tinytest.add('blocking', function (test) {
99
test.isTrue(isDefined, "blocking is not defined");
1010
test.isTrue(Package['peerlibrary:blocking'].blocking, "Package.peerlibrary:blocking.blocking is not defined");
1111

12-
test.equal(blocking(function (a, b, cb) { cb(null, a + b) })(1, 2), 3);
12+
var blockingFunction = blocking(function (a, b, cb) { cb(null, a + b) });
1313

14+
// We run it twice to catch possible bugs of reusing old futures.
15+
test.equal(blockingFunction(1, 2), 3);
16+
test.equal(blockingFunction(1, 2), 3);
17+
18+
// We want to support the last argument of a blocking function being a function
19+
// (and not switch to a non-blocking mode like Meteor.wrapAsync does).
1420
test.equal(blocking(function (a, b, f, cb) { cb(null, f(a, b)) })(1, 2, function (a, b) {return a + b}), 3);
1521

22+
// We want to work also with varargs functions .
1623
test.equal(blocking(function () {
1724
var a = arguments[0];
1825
var b = arguments[1];

0 commit comments

Comments
 (0)