Skip to content

Commit

Permalink
Added a send method to the public API, presently undocumented.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Dec 22, 2010
1 parent b8bd4dd commit fdddfc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

Next
- Added a send(value, op, args) method to the public API, for
forwarding messages to a value or promise in a future turn.

0.1.9
- Added isRejected() for testing whether a value is a rejected
promise. isResolved() retains the behavior of stating
Expand Down
28 changes: 20 additions & 8 deletions lib/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,31 @@ exports.asap = function (value, resolved, rejected) {
* "Method" constructs methods like "get(promise, name)" and "put(promise)".
*/
exports.Method = Method;
function Method (methodName) {
function Method (op) {
return function (object) {
var deferred = defer();
var args = Array.prototype.slice.call(arguments, 1);
forward.apply(undefined, [
ref(object),
methodName,
deferred.resolve
].concat(args));
return deferred.promise;
return send(object, op, args);
};
}

/**
* sends a message to a value in a future turn
* @param object* the recipient
* @param op the name of the message operation, e.g., "when",
* @param args {Array} an array of further arguments
* @returns result {Promise} a promise for the result of the operation
*/
exports.send = send;
function send(object, op, args) {
var deferred = defer();
forward.apply(undefined, [
ref(object),
op,
deferred.resolve
].concat(args));
return deferred.promise;
}

/**
* Gets the value of a property in a future turn.
* @param object promise or immediate reference for target object
Expand Down

0 comments on commit fdddfc9

Please sign in to comment.