Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Mukul
jio
Commits
308876d2
Commit
308876d2
authored
Sep 05, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise doesn't use try catch anymore
parent
07f22788
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
81 deletions
+84
-81
src/jio/core/Promise.js
src/jio/core/Promise.js
+84
-81
No files found.
src/jio/core/Promise.js
View file @
308876d2
...
...
@@ -88,11 +88,11 @@ Promise.error = function (value, onError) {
*/
Promise
.
get
=
function
(
dict
,
property
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
try
{
//
try {
solver
.
resolve
(
dict
[
property
]);
}
catch
(
e
)
{
solver
.
reject
(
e
);
}
//
} catch (e) {
//
solver.reject(e);
//
}
return
p
;
};
...
...
@@ -116,12 +116,12 @@ Promise.get = function (dict, property) {
*/
Promise
.
put
=
function
(
dict
,
property
,
value
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
try
{
//
try {
dict
[
property
]
=
value
;
solver
.
resolve
(
dict
[
property
]);
}
catch
(
e
)
{
solver
.
reject
(
e
);
}
//
} catch (e) {
//
solver.reject(e);
//
}
return
p
;
};
...
...
@@ -140,13 +140,14 @@ Promise.put = function (dict, property, value) {
* @return {Promise} The promise
*/
Promise
.
execute
=
function
(
callback
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
try
{
Promise
.
when
(
callback
(),
solver
.
resolve
,
solver
.
reject
);
}
catch
(
e
)
{
solver
.
reject
(
e
);
}
return
p
;
// var p = new Promise(), solver = p.defer();
// try {
// Promise.when(callback(), solver.resolve, solver.reject);
// } catch (e) {
// solver.reject(e);
// }
// return p;
return
Promise
.
when
(
callback
());
};
/**
...
...
@@ -369,9 +370,9 @@ Promise.prototype.defer = function (callback) {
setTimeout
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
try
{
//
try {
array
[
i
].
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
}
});
// free the memory
...
...
@@ -389,9 +390,9 @@ Promise.prototype.defer = function (callback) {
setTimeout
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
try
{
//
try {
array
[
i
].
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
}
});
// free the memory
...
...
@@ -404,9 +405,9 @@ Promise.prototype.defer = function (callback) {
if
(
that
.
_onProgress
)
{
var
i
;
for
(
i
=
0
;
i
<
that
.
_onProgress
.
length
;
i
+=
1
)
{
try
{
//
try {
that
.
_onProgress
[
i
].
apply
(
that
,
arguments
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
}
}
}
...
...
@@ -448,15 +449,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
case
"
resolved
"
:
if
(
typeof
onSuccess
===
'
function
'
)
{
setTimeout
(
function
()
{
try
{
//
try {
Promise
.
when
(
onSuccess
.
apply
(
that
,
that
.
_answers
),
resolver
.
resolve
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
//
} catch (e) {
//
resolver.reject(e);
//
}
});
}
else
{
setTimeout
(
function
()
{
...
...
@@ -467,15 +468,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
case
"
rejected
"
:
if
(
typeof
onError
===
'
function
'
)
{
setTimeout
(
function
()
{
try
{
//
try {
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
//
} catch (e) {
//
resolver.reject(e);
//
}
});
}
else
{
setTimeout
(
function
()
{
...
...
@@ -486,15 +487,16 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
default
:
if
(
typeof
onSuccess
===
'
function
'
)
{
this
.
_onResolve
.
push
(
function
()
{
try
{
//
try {
Promise
.
when
(
onSuccess
.
apply
(
that
,
arguments
),
resolver
.
resolve
,
resolver
.
reject
resolver
.
reject
,
resolver
.
notify
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
//
} catch (e) {
//
resolver.reject(e);
//
}
});
}
else
{
this
.
_onResolve
.
push
(
function
()
{
...
...
@@ -503,15 +505,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
}
if
(
typeof
onError
===
'
function
'
)
{
this
.
_onReject
.
push
(
function
()
{
try
{
//
try {
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
//
} catch (e) {
//
resolver.reject(e);
//
}
});
}
else
{
this
.
_onReject
.
push
(
function
()
{
...
...
@@ -520,17 +522,18 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
}
if
(
typeof
onProgress
===
'
function
'
)
{
this
.
_onProgress
.
push
(
function
()
{
var
result
;
try
{
result
=
onProgress
.
apply
(
that
,
arguments
);
var
result
=
onProgress
.
apply
(
that
,
arguments
);
// var result;
// try {
// result = onProgress.apply(that, arguments);
if
(
result
===
undefined
)
{
resolver
.
notify
.
apply
(
that
,
arguments
);
}
else
{
resolver
.
notify
(
result
);
}
}
catch
(
e
)
{
resolver
.
notify
.
apply
(
that
,
arguments
);
}
//
} catch (e) {
//
resolver.notify.apply(that, arguments);
//
}
});
}
else
{
this
.
_onProgress
.
push
(
function
()
{
...
...
@@ -595,9 +598,9 @@ Promise.prototype.done = function (callback) {
switch
(
this
.
_state
)
{
case
"
resolved
"
:
setTimeout
(
function
()
{
try
{
//
try {
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
});
break
;
case
"
rejected
"
:
...
...
@@ -630,9 +633,9 @@ Promise.prototype.fail = function (callback) {
switch
(
this
.
_state
)
{
case
"
rejected
"
:
setTimeout
(
function
()
{
try
{
//
try {
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
});
break
;
case
"
resolved
"
:
...
...
@@ -695,9 +698,9 @@ Promise.prototype.always = function (callback) {
case
"
resolved
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
try
{
//
try {
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
//
} catch (ignore) {}
});
break
;
default
:
...
...
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