Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
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
Alexandra Rogova
jio_mebibou
Commits
bfef5658
Commit
bfef5658
authored
Aug 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise.js then chain breaks -> fixed
parent
f3880058
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 @
bfef5658
...
...
@@ -440,53 +440,79 @@ Promise.prototype.defer = function (callback) {
* @return {Promise} The new promise
*/
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
)
{
case
"
resolved
"
:
if
(
typeof
onSuccess
===
'
function
'
)
{
next
.
defer
(
function
(
resolver
)
{
setTimeout
(
function
(
)
{
try
{
resolver
.
resolve
(
onSuccess
.
apply
(
that
,
that
.
_answers
));
Promise
.
when
(
onSuccess
.
apply
(
that
,
that
.
_answers
),
resolver
.
resolve
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
}
else
{
setTimeout
(
function
()
{
resolver
.
resolve
();
});
}
break
;
case
"
rejected
"
:
if
(
typeof
onError
===
'
function
'
)
{
next
.
defer
(
function
(
resolver
)
{
setTimeout
(
function
(
)
{
try
{
resolver
.
resolve
(
onError
.
apply
(
that
,
that
.
_answers
));
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
}
else
{
setTimeout
(
function
()
{
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
});
}
break
;
default
:
if
(
typeof
onSuccess
===
'
function
'
)
{
this
.
_onResolve
.
push
(
function
()
{
var
answers
=
arguments
;
next
.
defer
(
function
(
resolver
)
{
try
{
resolver
.
resolve
(
onSuccess
.
apply
(
that
,
answers
));
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
try
{
Promise
.
when
(
onSuccess
.
apply
(
that
,
arguments
),
resolver
.
resolve
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
}
else
{
this
.
_onResolve
.
push
(
function
()
{
resolver
.
resolve
();
});
}
if
(
typeof
onError
===
'
function
'
)
{
this
.
_onReject
.
push
(
function
()
{
var
answers
=
arguments
;
next
.
defer
(
function
(
resolver
)
{
try
{
resolver
.
resolve
(
onError
.
apply
(
that
,
answers
));
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
try
{
Promise
.
when
(
onError
.
apply
(
that
,
that
.
_answers
),
resolver
.
reject
,
resolver
.
reject
);
}
catch
(
e
)
{
resolver
.
reject
(
e
);
}
});
}
else
{
this
.
_onReject
.
push
(
function
()
{
resolver
.
reject
.
apply
(
resolver
,
that
.
_answers
);
});
}
if
(
typeof
onProgress
===
'
function
'
)
{
...
...
@@ -550,7 +576,9 @@ Promise.prototype.done = function (callback) {
switch
(
this
.
_state
)
{
case
"
resolved
"
:
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
});
break
;
case
"
rejected
"
:
...
...
@@ -583,7 +611,9 @@ Promise.prototype.fail = function (callback) {
switch
(
this
.
_state
)
{
case
"
rejected
"
:
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
catch
(
ignore
)
{}
});
break
;
case
"
resolved
"
:
...
...
@@ -646,7 +676,9 @@ Promise.prototype.always = function (callback) {
case
"
resolved
"
:
case
"
rejected
"
:
setTimeout
(
function
()
{
callback
.
apply
(
that
,
that
.
_answers
);
try
{
callback
.
apply
(
that
,
that
.
_answers
);
}
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