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) {
...
@@ -49,6 +49,7 @@ var Promise = function(resolver, canceller) {
// For now, simply reject the promise and does not propagate the cancel
// For now, simply reject the promise and does not propagate the cancel
// to parent or children
// to parent or children
if
(
resolved
)
{
return
;
}
if
(
resolved
)
{
return
;
}
promise
.
isCancelled
=
true
;
if
(
canceller
!==
undefined
)
{
if
(
canceller
!==
undefined
)
{
try
{
try
{
canceller
();
canceller
();
...
@@ -80,6 +81,7 @@ var invokeCallback = function(type, promise, callback, event) {
...
@@ -80,6 +81,7 @@ var invokeCallback = function(type, promise, callback, event) {
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
if
(
promise
.
isCancelled
)
{
return
;
}
if
(
hasCallback
)
{
if
(
hasCallback
)
{
try
{
try
{
...
@@ -110,6 +112,7 @@ var invokeCallback = function(type, promise, callback, event) {
...
@@ -110,6 +112,7 @@ var invokeCallback = function(type, promise, callback, event) {
Promise
.
prototype
=
{
Promise
.
prototype
=
{
constructor
:
Promise
,
constructor
:
Promise
,
isCancelled
:
undefined
,
isRejected
:
undefined
,
isRejected
:
undefined
,
isFulfilled
:
undefined
,
isFulfilled
:
undefined
,
rejectedReason
:
undefined
,
rejectedReason
:
undefined
,
...
...
test/tests/extension_test.js
View file @
a6b294f3
...
@@ -1513,6 +1513,7 @@ describe("RSVP extensions", function() {
...
@@ -1513,6 +1513,7 @@ describe("RSVP extensions", function() {
wrapped
.
cancel
();
wrapped
.
cancel
();
});
});
});
});
});
});
});
});
...
@@ -1734,14 +1735,16 @@ describe("`cancel` on promise created by then", function () {
...
@@ -1734,14 +1735,16 @@ describe("`cancel` on promise created by then", function () {
});
});
it
(
'
should stop parent fulFillment propagation
'
,
function
(
done
)
{
it
(
'
should stop parent fulFillment propagation
'
,
function
(
done
)
{
var
promise
=
new
RSVP
.
resolve
(
1
),
var
resolve_count
=
0
,
promise2
=
promise
.
then
();
promise
=
new
RSVP
.
resolve
(
1
),
promise2
=
promise
.
then
(
function
()
{
resolve_count
+=
1
;});
promise2
.
cancel
(
"
Foo
"
);
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
resolve_count
,
0
);
done
();
done
();
},
20
);
},
20
);
});
});
...
@@ -1756,12 +1759,12 @@ describe("`cancel` on promise created by then", function () {
...
@@ -1756,12 +1759,12 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
reject_count
,
1
);
assert
.
equal
(
reject_count
,
0
);
done
();
done
();
},
20
);
},
20
);
});
});
it
(
'
should
not
be callable twice
'
,
function
(
done
)
{
it
(
'
should be callable twice
'
,
function
(
done
)
{
var
reject_count
=
0
,
var
reject_count
=
0
,
promise
=
new
RSVP
.
reject
(
1
),
promise
=
new
RSVP
.
reject
(
1
),
promise2
=
promise
.
fail
(
function
()
{
reject_count
+=
1
;});
promise2
=
promise
.
fail
(
function
()
{
reject_count
+=
1
;});
...
@@ -1772,7 +1775,7 @@ describe("`cancel` on promise created by then", function () {
...
@@ -1772,7 +1775,7 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
reject_count
,
1
);
assert
.
equal
(
reject_count
,
0
);
done
();
done
();
},
20
);
},
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