mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 08:57:03 +03:00
Promises (first look)
Thread dropdown Small fixes
This commit is contained in:
parent
dd41d30f9b
commit
c23ba31e17
61 changed files with 12442 additions and 130 deletions
48
vendors/Q/design/q4.js
vendored
Normal file
48
vendors/Q/design/q4.js
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
var isPromise = function (value) {
|
||||
return value && typeof value.then === "function";
|
||||
};
|
||||
|
||||
var defer = function () {
|
||||
var pending = [], value;
|
||||
return {
|
||||
resolve: function (_value) {
|
||||
if (pending) {
|
||||
value = ref(_value); // values wrapped in a promise
|
||||
for (var i = 0, ii = pending.length; i < ii; i++) {
|
||||
var callback = pending[i];
|
||||
value.then(callback); // then called instead
|
||||
}
|
||||
pending = undefined;
|
||||
}
|
||||
},
|
||||
promise: {
|
||||
then: function (_callback) {
|
||||
var result = defer();
|
||||
// callback is wrapped so that its return
|
||||
// value is captured and used to resolve the promise
|
||||
// that "then" returns
|
||||
var callback = function (value) {
|
||||
result.resolve(_callback(value));
|
||||
};
|
||||
if (pending) {
|
||||
pending.push(callback);
|
||||
} else {
|
||||
value.then(callback);
|
||||
}
|
||||
return result.promise;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var ref = function (value) {
|
||||
if (value && typeof value.then === "function")
|
||||
return value;
|
||||
return {
|
||||
then: function (callback) {
|
||||
return ref(callback(value));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue