michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-common/async.js"); michael@0: michael@0: function run_test() { michael@0: _("Chain a few async methods, making sure the 'this' object is correct."); michael@0: michael@0: let methods = { michael@0: save: function(x, callback) { michael@0: this.x = x; michael@0: callback(x); michael@0: }, michael@0: addX: function(x, callback) { michael@0: callback(x + this.x); michael@0: }, michael@0: double: function(x, callback) { michael@0: callback(x * 2); michael@0: }, michael@0: neg: function(x, callback) { michael@0: callback(-x); michael@0: } michael@0: }; michael@0: methods.chain = Async.chain; michael@0: michael@0: // ((1 + 1 + 1) * (-1) + 1) * 2 + 1 = -3 michael@0: methods.chain(methods.save, methods.addX, methods.addX, methods.neg, michael@0: methods.addX, methods.double, methods.addX, methods.save)(1); michael@0: do_check_eq(methods.x, -3); michael@0: }