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
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
6113c5a2
Commit
6113c5a2
authored
Sep 12, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise callback try catch are useful
parent
2ac95e1d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
84 deletions
+82
-84
src/jio/core/Promise.js
src/jio/core/Promise.js
+82
-84
No files found.
src/jio/core/Promise.js
View file @
6113c5a2
...
@@ -120,11 +120,11 @@ Promise.success = function (item, onSuccess) {
...
@@ -120,11 +120,11 @@ Promise.success = function (item, onSuccess) {
*/
*/
Promise
.
get
=
function
(
dict
,
property
)
{
Promise
.
get
=
function
(
dict
,
property
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
//
try {
try
{
solver
.
resolve
(
dict
[
property
]);
solver
.
resolve
(
dict
[
property
]);
//
} catch (e) {
}
catch
(
e
)
{
//
solver.reject(e);
solver
.
reject
(
e
);
//
}
}
return
p
;
return
p
;
};
};
...
@@ -148,12 +148,12 @@ Promise.get = function (dict, property) {
...
@@ -148,12 +148,12 @@ Promise.get = function (dict, property) {
*/
*/
Promise
.
put
=
function
(
dict
,
property
,
value
)
{
Promise
.
put
=
function
(
dict
,
property
,
value
)
{
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
//
try {
try
{
dict
[
property
]
=
value
;
dict
[
property
]
=
value
;
solver
.
resolve
(
dict
[
property
]);
solver
.
resolve
(
dict
[
property
]);
//
} catch (e) {
}
catch
(
e
)
{
//
solver.reject(e);
solver
.
reject
(
e
);
//
}
}
return
p
;
return
p
;
};
};
...
@@ -172,14 +172,13 @@ Promise.put = function (dict, property, value) {
...
@@ -172,14 +172,13 @@ Promise.put = function (dict, property, value) {
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
Promise
.
execute
=
function
(
callback
)
{
Promise
.
execute
=
function
(
callback
)
{
// var p = new Promise(), solver = p.defer();
var
p
=
new
Promise
(),
solver
=
p
.
defer
();
// try {
try
{
// Promise.when(callback(), solver.resolve, solver.reject);
Promise
.
when
(
callback
(),
solver
.
resolve
,
solver
.
reject
);
// } catch (e) {
}
catch
(
e
)
{
// solver.reject(e);
solver
.
reject
(
e
);
// }
}
// return p;
return
p
;
return
Promise
.
when
(
callback
());
};
};
/**
/**
...
@@ -406,9 +405,9 @@ Promise.prototype.defer = function (callback) {
...
@@ -406,9 +405,9 @@ Promise.prototype.defer = function (callback) {
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
i
;
var
i
;
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
//
try {
try
{
array
[
i
].
apply
(
that
,
that
.
_answers
);
array
[
i
].
apply
(
that
,
that
.
_answers
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
}
}
});
});
// free the memory
// free the memory
...
@@ -426,9 +425,9 @@ Promise.prototype.defer = function (callback) {
...
@@ -426,9 +425,9 @@ Promise.prototype.defer = function (callback) {
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
i
;
var
i
;
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
//
try {
try
{
array
[
i
].
apply
(
that
,
that
.
_answers
);
array
[
i
].
apply
(
that
,
that
.
_answers
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
}
}
});
});
// free the memory
// free the memory
...
@@ -441,9 +440,9 @@ Promise.prototype.defer = function (callback) {
...
@@ -441,9 +440,9 @@ Promise.prototype.defer = function (callback) {
if
(
that
.
_onProgress
)
{
if
(
that
.
_onProgress
)
{
var
i
;
var
i
;
for
(
i
=
0
;
i
<
that
.
_onProgress
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
that
.
_onProgress
.
length
;
i
+=
1
)
{
//
try {
try
{
that
.
_onProgress
[
i
].
apply
(
that
,
arguments
);
that
.
_onProgress
[
i
].
apply
(
that
,
arguments
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
}
}
}
}
}
}
...
@@ -485,15 +484,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
...
@@ -485,15 +484,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
case
"
resolved
"
:
case
"
resolved
"
:
if
(
typeof
onSuccess
===
'
function
'
)
{
if
(
typeof
onSuccess
===
'
function
'
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
//
try {
try
{
Promise
.
when
(
Promise
.
when
(
onSuccess
.
apply
(
that
,
that
.
_answers
),
onSuccess
.
apply
(
that
,
that
.
_answers
),
resolver
.
resolve
,
resolver
.
resolve
,
resolver
.
reject
resolver
.
reject
);
);
//
} catch (e) {
}
catch
(
e
)
{
//
resolver.reject(e);
resolver
.
reject
(
e
);
//
}
}
});
});
}
else
{
}
else
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
...
@@ -505,18 +504,18 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
...
@@ -505,18 +504,18 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
if
(
typeof
onError
===
'
function
'
)
{
if
(
typeof
onError
===
'
function
'
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
result
=
onError
.
apply
(
that
,
that
.
_answers
);
var
result
=
onError
.
apply
(
that
,
that
.
_answers
);
// try {
if
(
result
===
undefined
)
{
if
(
result
===
undefined
)
{
return
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
return
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
}
}
try
{
Promise
.
when
(
Promise
.
when
(
result
,
result
,
resolver
.
reject
,
resolver
.
reject
,
resolver
.
reject
resolver
.
reject
);
);
//
} catch (e) {
}
catch
(
e
)
{
//
resolver.reject(e);
resolver
.
reject
(
e
);
//
}
}
});
});
}
else
{
}
else
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
...
@@ -527,16 +526,16 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
...
@@ -527,16 +526,16 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
default
:
default
:
if
(
typeof
onSuccess
===
'
function
'
)
{
if
(
typeof
onSuccess
===
'
function
'
)
{
this
.
_onResolve
.
push
(
function
()
{
this
.
_onResolve
.
push
(
function
()
{
//
try {
try
{
Promise
.
when
(
Promise
.
when
(
onSuccess
.
apply
(
that
,
arguments
),
onSuccess
.
apply
(
that
,
arguments
),
resolver
.
resolve
,
resolver
.
resolve
,
resolver
.
reject
,
resolver
.
reject
,
resolver
.
notify
resolver
.
notify
);
);
//
} catch (e) {
}
catch
(
e
)
{
//
resolver.reject(e);
resolver
.
reject
(
e
);
//
}
}
});
});
}
else
{
}
else
{
this
.
_onResolve
.
push
(
function
()
{
this
.
_onResolve
.
push
(
function
()
{
...
@@ -545,15 +544,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
...
@@ -545,15 +544,15 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
}
}
if
(
typeof
onError
===
'
function
'
)
{
if
(
typeof
onError
===
'
function
'
)
{
this
.
_onReject
.
push
(
function
()
{
this
.
_onReject
.
push
(
function
()
{
//
try {
try
{
Promise
.
when
(
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
,
resolver
.
reject
resolver
.
reject
);
);
//
} catch (e) {
}
catch
(
e
)
{
//
resolver.reject(e);
resolver
.
reject
(
e
);
//
}
}
});
});
}
else
{
}
else
{
this
.
_onReject
.
push
(
function
()
{
this
.
_onReject
.
push
(
function
()
{
...
@@ -562,18 +561,17 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
...
@@ -562,18 +561,17 @@ Promise.prototype.then = function (onSuccess, onError, onProgress) {
}
}
if
(
typeof
onProgress
===
'
function
'
)
{
if
(
typeof
onProgress
===
'
function
'
)
{
this
.
_onProgress
.
push
(
function
()
{
this
.
_onProgress
.
push
(
function
()
{
var
result
=
onProgress
.
apply
(
that
,
arguments
);
var
result
;
// var result;
try
{
// try {
result
=
onProgress
.
apply
(
that
,
arguments
);
// result = onProgress.apply(that, arguments);
if
(
result
===
undefined
)
{
if
(
result
===
undefined
)
{
resolver
.
notify
.
apply
(
that
,
arguments
);
resolver
.
notify
.
apply
(
that
,
arguments
);
}
else
{
}
else
{
resolver
.
notify
(
result
);
resolver
.
notify
(
result
);
}
}
//
} catch (e) {
}
catch
(
e
)
{
//
resolver.notify.apply(that, arguments);
resolver
.
notify
.
apply
(
that
,
arguments
);
//
}
}
});
});
}
else
{
}
else
{
this
.
_onProgress
.
push
(
function
()
{
this
.
_onProgress
.
push
(
function
()
{
...
@@ -638,9 +636,9 @@ Promise.prototype.done = function (callback) {
...
@@ -638,9 +636,9 @@ Promise.prototype.done = function (callback) {
switch
(
this
.
_state
)
{
switch
(
this
.
_state
)
{
case
"
resolved
"
:
case
"
resolved
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
//
try {
try
{
callback
.
apply
(
that
,
that
.
_answers
);
callback
.
apply
(
that
,
that
.
_answers
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
});
});
break
;
break
;
case
"
rejected
"
:
case
"
rejected
"
:
...
@@ -673,9 +671,9 @@ Promise.prototype.fail = function (callback) {
...
@@ -673,9 +671,9 @@ Promise.prototype.fail = function (callback) {
switch
(
this
.
_state
)
{
switch
(
this
.
_state
)
{
case
"
rejected
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
//
try {
try
{
callback
.
apply
(
that
,
that
.
_answers
);
callback
.
apply
(
that
,
that
.
_answers
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
});
});
break
;
break
;
case
"
resolved
"
:
case
"
resolved
"
:
...
@@ -738,9 +736,9 @@ Promise.prototype.always = function (callback) {
...
@@ -738,9 +736,9 @@ Promise.prototype.always = function (callback) {
case
"
resolved
"
:
case
"
resolved
"
:
case
"
rejected
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
//
try {
try
{
callback
.
apply
(
that
,
that
.
_answers
);
callback
.
apply
(
that
,
that
.
_answers
);
// } catch (ignore) {}
}
catch
(
ignore
)
{}
// errors will never be retrieved by global
});
});
break
;
break
;
default
:
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