Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
jio
Commits
65f14100
Commit
65f14100
authored
Aug 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise.js perf increased
parent
2d2e48d4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
30 deletions
+29
-30
src/jio/core/Promise.js
src/jio/core/Promise.js
+29
-30
No files found.
src/jio/core/Promise.js
View file @
65f14100
...
@@ -140,13 +140,13 @@ Promise.put = function (dict, property, value) {
...
@@ -140,13 +140,13 @@ Promise.put = function (dict, property, value) {
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
Promise
.
execute
=
function
(
callback
)
{
Promise
.
execute
=
function
(
callback
)
{
return
new
Promise
().
defer
(
function
(
solver
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
try
{
try
{
solver
.
resolve
(
callback
()
);
Promise
.
when
(
callback
(),
solver
.
resolve
,
solver
.
reject
);
}
catch
(
e
)
{
}
catch
(
e
)
{
solver
.
reject
(
e
);
solver
.
reject
(
e
);
}
}
})
;
return
p
;
};
};
/**
/**
...
@@ -164,7 +164,7 @@ Promise.execute = function (callback) {
...
@@ -164,7 +164,7 @@ Promise.execute = function (callback) {
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
Promise
.
all
=
function
(
items
)
{
Promise
.
all
=
function
(
items
)
{
var
array
=
[],
count
=
0
,
next
=
new
Promise
(),
solver
;
var
array
=
[],
count
=
0
,
next
=
new
Promise
(),
solver
,
i
;
solver
=
next
.
defer
();
solver
=
next
.
defer
();
function
succeed
(
i
)
{
function
succeed
(
i
)
{
return
function
(
answer
)
{
return
function
(
answer
)
{
...
@@ -176,9 +176,9 @@ Promise.all = function (items) {
...
@@ -176,9 +176,9 @@ Promise.all = function (items) {
return
solver
.
resolve
(
array
);
return
solver
.
resolve
(
array
);
};
};
}
}
items
.
forEach
(
function
(
item
,
i
)
{
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
Promise
.
when
(
item
).
done
(
succeed
(
i
)).
fail
(
succeed
(
i
));
Promise
.
when
(
item
s
[
i
],
succeed
(
i
),
succeed
(
i
));
}
);
}
return
next
;
return
next
;
};
};
...
@@ -201,14 +201,14 @@ Promise.allOrNone = function (items) {
...
@@ -201,14 +201,14 @@ Promise.allOrNone = function (items) {
var
array
=
[],
count
=
0
,
next
=
new
Promise
(),
solver
;
var
array
=
[],
count
=
0
,
next
=
new
Promise
(),
solver
;
solver
=
next
.
defer
();
solver
=
next
.
defer
();
items
.
forEach
(
function
(
item
,
i
)
{
items
.
forEach
(
function
(
item
,
i
)
{
Promise
.
when
(
item
).
done
(
function
(
answer
)
{
Promise
.
when
(
item
,
function
(
answer
)
{
array
[
i
]
=
answer
;
array
[
i
]
=
answer
;
count
+=
1
;
count
+=
1
;
if
(
count
!==
items
.
length
)
{
if
(
count
!==
items
.
length
)
{
return
;
return
;
}
}
return
solver
.
resolve
(
array
);
return
solver
.
resolve
(
array
);
}
).
fail
(
function
(
answer
)
{
}
,
function
(
answer
)
{
return
solver
.
reject
(
answer
);
return
solver
.
reject
(
answer
);
});
});
});
});
...
@@ -230,18 +230,17 @@ Promise.allOrNone = function (items) {
...
@@ -230,18 +230,17 @@ Promise.allOrNone = function (items) {
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
Promise
.
any
=
function
(
items
)
{
Promise
.
any
=
function
(
items
)
{
var
count
=
0
,
next
=
new
Promise
(),
solver
;
var
count
=
0
,
next
=
new
Promise
(),
solver
,
i
;
solver
=
next
.
defer
();
solver
=
next
.
defer
();
items
.
forEach
(
function
(
item
)
{
function
onError
(
answer
)
{
Promise
.
when
(
item
).
done
(
function
(
answer
)
{
return
solver
.
resolve
(
answer
);
}).
fail
(
function
(
answer
)
{
count
+=
1
;
count
+=
1
;
if
(
count
===
items
.
length
)
{
if
(
count
===
items
.
length
)
{
return
solver
.
reject
(
answer
);
solver
.
reject
(
answer
);
}
}
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
Promise
.
when
(
items
[
i
],
solver
.
resolve
,
onError
);
}
}
});
});
return
next
;
return
next
;
};
};
...
@@ -259,10 +258,10 @@ Promise.any = function (items) {
...
@@ -259,10 +258,10 @@ Promise.any = function (items) {
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
Promise
.
first
=
function
(
items
)
{
// *promises
Promise
.
first
=
function
(
items
)
{
// *promises
var
next
=
new
Promise
(),
solver
=
next
.
defer
();
var
next
=
new
Promise
(),
solver
=
next
.
defer
()
,
i
;
items
.
forEach
(
function
(
item
)
{
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
Promise
.
when
(
item
).
done
(
solver
.
resolve
).
fail
(
solver
.
reject
);
Promise
.
when
(
item
s
[
i
],
solver
.
resolve
,
solver
.
reject
);
}
);
}
return
next
;
return
next
;
};
};
...
@@ -325,10 +324,10 @@ Promise.timeout = function (item, timeout) {
...
@@ -325,10 +324,10 @@ Promise.timeout = function (item, timeout) {
i
=
setTimeout
(
function
()
{
i
=
setTimeout
(
function
()
{
solver
.
reject
.
apply
(
next
,
[
new
Error
(
"
Timeout
"
)]);
solver
.
reject
.
apply
(
next
,
[
new
Error
(
"
Timeout
"
)]);
},
timeout
);
},
timeout
);
Promise
.
when
(
item
).
done
(
function
()
{
Promise
.
when
(
item
,
function
()
{
clearTimeout
(
i
);
clearTimeout
(
i
);
solver
.
resolve
.
apply
(
next
,
arguments
);
solver
.
resolve
.
apply
(
next
,
arguments
);
}
).
fail
(
function
()
{
}
,
function
()
{
clearTimeout
(
i
);
clearTimeout
(
i
);
solver
.
reject
.
apply
(
next
,
arguments
);
solver
.
reject
.
apply
(
next
,
arguments
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment