Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rsvp.js
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
rsvp.js
Commits
a6b294f3
Commit
a6b294f3
authored
Feb 24, 2020
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise: cancelling a promise created with .then stop parent propagation
parent
a61853dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
lib/rsvp/promise.js
lib/rsvp/promise.js
+3
-0
test/tests/extension_test.js
test/tests/extension_test.js
+8
-5
No files found.
lib/rsvp/promise.js
View file @
a6b294f3
...
...
@@ -49,6 +49,7 @@ var Promise = function(resolver, canceller) {
// For now, simply reject the promise and does not propagate the cancel
// to parent or children
if
(
resolved
)
{
return
;
}
promise
.
isCancelled
=
true
;
if
(
canceller
!==
undefined
)
{
try
{
canceller
();
...
...
@@ -80,6 +81,7 @@ var invokeCallback = function(type, promise, callback, event) {
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
if
(
promise
.
isCancelled
)
{
return
;
}
if
(
hasCallback
)
{
try
{
...
...
@@ -110,6 +112,7 @@ var invokeCallback = function(type, promise, callback, event) {
Promise
.
prototype
=
{
constructor
:
Promise
,
isCancelled
:
undefined
,
isRejected
:
undefined
,
isFulfilled
:
undefined
,
rejectedReason
:
undefined
,
...
...
test/tests/extension_test.js
View file @
a6b294f3
...
...
@@ -1513,6 +1513,7 @@ describe("RSVP extensions", function() {
wrapped
.
cancel
();
});
});
});
});
...
...
@@ -1734,14 +1735,16 @@ describe("`cancel` on promise created by then", function () {
});
it
(
'
should stop parent fulFillment propagation
'
,
function
(
done
)
{
var
promise
=
new
RSVP
.
resolve
(
1
),
promise2
=
promise
.
then
();
var
resolve_count
=
0
,
promise
=
new
RSVP
.
resolve
(
1
),
promise2
=
promise
.
then
(
function
()
{
resolve_count
+=
1
;});
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
resolve_count
,
0
);
done
();
},
20
);
});
...
...
@@ -1756,12 +1759,12 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
reject_count
,
1
);
assert
.
equal
(
reject_count
,
0
);
done
();
},
20
);
});
it
(
'
should
not
be callable twice
'
,
function
(
done
)
{
it
(
'
should be callable twice
'
,
function
(
done
)
{
var
reject_count
=
0
,
promise
=
new
RSVP
.
reject
(
1
),
promise2
=
promise
.
fail
(
function
()
{
reject_count
+=
1
;});
...
...
@@ -1772,7 +1775,7 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
reject_count
,
1
);
assert
.
equal
(
reject_count
,
0
);
done
();
},
20
);
});
...
...
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