projects
/
platform
/
framework
/
web
/
crosswalk.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
- add sources.
[platform/framework/web/crosswalk.git]
/
src
/
chrome
/
test
/
data
/
third_party
/
spaceport
/
js
/
util
/
quickPromise.js
1
define([ 'util/ensureCallback' ], function (ensureCallback) {
2
function quickPromise() {
3
var thens = [ ];
4
var resolved = false;
5
6
function resolve() {
7
if (resolved) {
8
throw new Error("Already resolved");
9
}
10
resolved = true;
11
12
while (thens.length) {
13
var fn = thens.pop();
14
fn();
15
}
16
}
17
18
function then(fn) {
19
fn = ensureCallback(fn);
20
if (resolved) {
21
fn();
22
} else {
23
thens.push(fn);
24
}
25
}
26
27
return {
28
resolve: resolve,
29
then: then
30
};
31
}
32
33
return quickPromise;
34
});