Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Q features assumed by smart-contract code #266

Closed
wants to merge 3 commits into from

3 participants

Mark S. Miller Kris Kowal Domenic Denicola
Mark S. Miller

No description provided.

q.js
((23 lines not shown))
+function passByCopy(obj) {
+ //freeze(obj);
+ //passByCopies.set(obj, true);
+ return obj;
+}
+
+/**
+ * Consider making this variadic
+ */
+Q.join = join;
+function join(x, y) {
+ return Q.all([x, y]).spread(function(x, y) {
+ if (x === y) {
+ // TODO: "===" should be Object.is or equiv
+ return x;
+ }
Kris Kowal Owner

Indentation issue here.

Domenic Denicola Collaborator
domenic added a note

Be sure to check for tabs; there were some of those in a81dbd4 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Kris Kowal kriskowal commented on the diff
((15 lines not shown))
return deferred.promise;
}
/**
+ * Will be relevant for remote
Kris Kowal Owner

Will need to make this something similar to Q.master, but with the opposite meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Domenic Denicola
Collaborator

doesn't work with IE :(

Collaborator

IE<=8 doesn't have forEach. We've been using fun hacks with array_reduce so far, e.g. https://github.com/kriskowal/q/blob/d97b311c18a18ae63bc8c552d0ff6d706da75a1b/q.js#L434-L438

Mark S. Miller

Hi @domenic, the array_reduce thing seems too heavy for something this simple, so I just converted to a for(;;) loop.

Kris Kowal
Owner

I’ve rolled this into #339 which should land for the next version.

Kris Kowal
Owner

These have been merged.

Kris Kowal kriskowal closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. Mark S. Miller
Commits on Apr 9, 2013
  1. Mark S. Miller
  2. Mark S. Miller

    damn tabs

    erights authored
This page is out of date. Refresh to see the latest.
Showing with 45 additions and 6 deletions.
  1. +45 −6 q.js
51 q.js
View
@@ -506,16 +506,55 @@ defer.prototype.makeNodeResolver = function () {
Q.promise = promise;
function promise(makePromise) {
var deferred = defer();
- fcall(
- makePromise,
- deferred.resolve,
- deferred.reject,
- deferred.notify
- ).fail(deferred.reject);
+ try {
+ makePromise(deferred.resolve, deferred.reject, deferred.notify);
+ } catch (reason) {
+ deferred.reject(reason);
+ }
return deferred.promise;
}
/**
+ * Will be relevant for remote
Kris Kowal Owner

Will need to make this something similar to Q.master, but with the opposite meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ */
+Q.passByCopy = passByCopy;
+//var passByCopies = WeakMap();
+function passByCopy(obj) {
+ //freeze(obj);
+ //passByCopies.set(obj, true);
+ return obj;
+}
+
+/**
+ * Consider making this variadic
+ */
+Q.join = join;
+function join(x, y) {
+ return Q.all([x, y]).spread(function(x, y) {
+ if (x === y) {
+ // TODO: "===" should be Object.is or equiv
+ return x;
+ }
+ throw new Error("not the same");
+ });
+}
+
+Q.race = race;
+function race(answerPs) {
+ return promise(function(resolve,reject) {
+// Switch to this once we can assume at least ES5
+// answerPs.forEach(function(answerP) {
+// Q(answerP).then(resolve,reject);
+// });
+// Use this in the meantime
+ for (var i = 0, len = answerPs.length; i < len; i++) {
+ Q(answerPs[i]).then(resolve,reject);
+ }
+ });
+}
+
+
+/**
* Constructs a Promise with a promise descriptor object and optional fallback
* function. The descriptor contains methods like when(rejected), get(name),
* set(name, value), post(name, args), and delete(name), which all
Something went wrong with that request. Please try again.