Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
e48ee2d9
Commit
e48ee2d9
authored
Aug 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise.js then chain breaks -> fixed
parent
fa7b93e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
24 deletions
+56
-24
src/jio/core/Promise.js
src/jio/core/Promise.js
+56
-24
No files found.
src/jio/core/Promise.js
View file @
e48ee2d9
...
@@ -440,53 +440,79 @@ Promise.prototype.defer = function (callback) {
...
@@ -440,53 +440,79 @@ Promise.prototype.defer = function (callback) {
* @return {Promise} The new promise
* @return {Promise} The new promise
*/
*/
Promise
.
prototype
.
then
=
function
(
onSuccess
,
onError
,
onProgress
)
{
Promise
.
prototype
.
then
=
function
(
onSuccess
,
onError
,
onProgress
)
{
var
next
=
new
Promise
(),
that
=
this
;
var
next
=
new
Promise
(),
that
=
this
,
resolver
=
next
.
defer
()
;
switch
(
this
.
_state
)
{
switch
(
this
.
_state
)
{
case
"
resolved
"
:
case
"
resolved
"
:
if
(
typeof
onSuccess
===
'
function
'
)
{
if
(
typeof
onSuccess
===
'
function
'
)
{
next
.
defer
(
function
(
resolver
)
{
setTimeout
(
function
(
)
{
try
{
try
{
resolver
.
resolve
(
onSuccess
.
apply
(
that
,
that
.
_answers
));
Promise
.
when
(
onSuccess
.
apply
(
that
,
that
.
_answers
),
resolver
.
resolve
,
resolver
.
reject
);
}
catch
(
e
)
{
}
catch
(
e
)
{
resolver
.
reject
(
e
);
resolver
.
reject
(
e
);
}
}
});
});
}
else
{
setTimeout
(
function
()
{
resolver
.
resolve
();
});
}
}
break
;
break
;
case
"
rejected
"
:
case
"
rejected
"
:
if
(
typeof
onError
===
'
function
'
)
{
if
(
typeof
onError
===
'
function
'
)
{
next
.
defer
(
function
(
resolver
)
{
setTimeout
(
function
(
)
{
try
{
try
{
resolver
.
resolve
(
onError
.
apply
(
that
,
that
.
_answers
));
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
);
}
catch
(
e
)
{
}
catch
(
e
)
{
resolver
.
reject
(
e
);
resolver
.
reject
(
e
);
}
}
});
});
}
else
{
setTimeout
(
function
()
{
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
});
}
}
break
;
break
;
default
:
default
:
if
(
typeof
onSuccess
===
'
function
'
)
{
if
(
typeof
onSuccess
===
'
function
'
)
{
this
.
_onResolve
.
push
(
function
()
{
this
.
_onResolve
.
push
(
function
()
{
var
answers
=
arguments
;
try
{
next
.
defer
(
function
(
resolver
)
{
Promise
.
when
(
try
{
onSuccess
.
apply
(
that
,
arguments
),
resolver
.
resolve
(
onSuccess
.
apply
(
that
,
answers
));
resolver
.
resolve
,
}
catch
(
e
)
{
resolver
.
reject
resolver
.
reject
(
e
);
);
}
}
catch
(
e
)
{
});
resolver
.
reject
(
e
);
}
});
}
else
{
this
.
_onResolve
.
push
(
function
()
{
resolver
.
resolve
();
});
});
}
}
if
(
typeof
onError
===
'
function
'
)
{
if
(
typeof
onError
===
'
function
'
)
{
this
.
_onReject
.
push
(
function
()
{
this
.
_onReject
.
push
(
function
()
{
var
answers
=
arguments
;
try
{
next
.
defer
(
function
(
resolver
)
{
Promise
.
when
(
try
{
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
resolve
(
onError
.
apply
(
that
,
answers
));
resolver
.
reject
,
}
catch
(
e
)
{
resolver
.
reject
resolver
.
reject
(
e
);
);
}
}
catch
(
e
)
{
});
resolver
.
reject
(
e
);
}
});
}
else
{
this
.
_onReject
.
push
(
function
()
{
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
});
});
}
}
if
(
typeof
onProgress
===
'
function
'
)
{
if
(
typeof
onProgress
===
'
function
'
)
{
...
@@ -550,7 +576,9 @@ Promise.prototype.done = function (callback) {
...
@@ -550,7 +576,9 @@ Promise.prototype.done = function (callback) {
switch
(
this
.
_state
)
{
switch
(
this
.
_state
)
{
case
"
resolved
"
:
case
"
resolved
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
});
});
break
;
break
;
case
"
rejected
"
:
case
"
rejected
"
:
...
@@ -583,7 +611,9 @@ Promise.prototype.fail = function (callback) {
...
@@ -583,7 +611,9 @@ Promise.prototype.fail = function (callback) {
switch
(
this
.
_state
)
{
switch
(
this
.
_state
)
{
case
"
rejected
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
});
});
break
;
break
;
case
"
resolved
"
:
case
"
resolved
"
:
...
@@ -646,7 +676,9 @@ Promise.prototype.always = function (callback) {
...
@@ -646,7 +676,9 @@ Promise.prototype.always = function (callback) {
case
"
resolved
"
:
case
"
resolved
"
:
case
"
rejected
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
});
});
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