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
fa862176
Commit
fa862176
authored
Dec 14, 2021
by
Romain Courteaud
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cancel: propagate cancel message to thenable
parent
69c6d7c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
9 deletions
+39
-9
lib/rsvp/promise.js
lib/rsvp/promise.js
+3
-3
test/tests/extension_test.js
test/tests/extension_test.js
+36
-6
No files found.
lib/rsvp/promise.js
View file @
fa862176
...
...
@@ -122,8 +122,8 @@ Promise.prototype = {
this
.
off
(
'
error
'
,
onerror
);
var
thenPromise
=
new
this
.
constructor
(
function
()
{},
function
()
{
thenPromise
.
trigger
(
'
promise:cancelled
'
,
{});
function
(
msg
)
{
thenPromise
.
trigger
(
'
promise:cancelled
'
,
{
msg
:
msg
});
});
if
(
this
.
isFulfilled
)
{
...
...
@@ -183,7 +183,7 @@ function handleThenable(promise, value) {
if
(
isFunction
(
then
))
{
promise
.
on
(
'
promise:cancelled
'
,
function
(
event
)
{
if
(
isFunction
(
value
.
cancel
))
{
value
.
cancel
();
value
.
cancel
(
event
.
msg
);
}
});
then
.
call
(
value
,
function
(
val
)
{
...
...
test/tests/extension_test.js
View file @
fa862176
...
...
@@ -593,8 +593,10 @@ describe("RSVP extensions", function() {
setTimeout
(
function
()
{
assert
(
first
.
isRejected
);
assert
(
first
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
first
.
rejectedReason
.
message
,
"
Foo
"
);
assert
(
second
.
isRejected
);
assert
(
second
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
second
.
rejectedReason
.
message
,
"
Foo
"
);
assert
.
equal
(
error
.
message
,
"
Foo
"
);
done
();
},
20
);
...
...
@@ -823,8 +825,10 @@ describe("RSVP extensions", function() {
setTimeout
(
function
()
{
assert
(
first
.
isRejected
);
assert
(
first
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
first
.
rejectedReason
.
message
,
"
Foo
"
);
assert
(
second
.
isRejected
);
assert
(
second
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
second
.
rejectedReason
.
message
,
"
Foo
"
);
assert
.
equal
(
error
.
message
,
"
Foo
"
);
done
();
},
20
);
...
...
@@ -1762,6 +1766,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
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
assert
.
equal
(
resolve_count
,
0
);
done
();
},
20
);
...
...
@@ -1777,6 +1782,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
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
assert
.
equal
(
reject_count
,
0
);
done
();
},
20
);
...
...
@@ -1793,6 +1799,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
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
assert
.
equal
(
reject_count
,
0
);
done
();
},
20
);
...
...
@@ -1821,10 +1828,12 @@ describe("`cancel` on promise created by then", function () {
it
(
'
should cancel the pending fulfilled promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
cancel_msg
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
();}),
promise2
=
promise
.
then
(
function
()
{
return
RSVP
.
Promise
(
function
()
{},
function
()
{
return
RSVP
.
Promise
(
function
()
{},
function
(
msg
)
{
cancel_called
=
true
;
cancel_msg
=
msg
;
});
});
...
...
@@ -1832,9 +1841,11 @@ describe("`cancel` on promise created by then", function () {
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
cancel_called
,
true
);
assert
.
equal
(
cancel_msg
,
"
Foo
"
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
done
();
},
20
);
},
20
);
...
...
@@ -1856,6 +1867,7 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
done
();
},
20
);
},
20
);
...
...
@@ -1866,10 +1878,12 @@ describe("`cancel` on promise created by then", function () {
describe
(
"
`cancel` on thenable created by then
"
,
function
()
{
it
(
'
should cancel the pending fulfilled promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
cancel_msg
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
();}),
promise2
=
promise
.
then
(
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
(
msg
)
{
cancel_called
=
true
;
cancel_msg
=
msg
;
}};
});
...
...
@@ -1877,9 +1891,11 @@ describe("`cancel` on thenable created by then", function () {
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
cancel_called
,
true
);
assert
.
equal
(
cancel_msg
,
"
Foo
"
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
done
();
},
20
);
},
20
);
...
...
@@ -1887,10 +1903,12 @@ describe("`cancel` on thenable created by then", function () {
it
(
'
should cancel the pending rejected promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
cancel_msg
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
reject
();}),
promise2
=
promise
.
then
(
undefined
,
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
(
msg
)
{
cancel_called
=
true
;
cancel_msg
=
msg
;
}};
});
...
...
@@ -1898,6 +1916,7 @@ describe("`cancel` on thenable created by then", function () {
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
cancel_called
,
true
);
assert
.
equal
(
cancel_msg
,
"
Foo
"
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
...
...
@@ -1921,6 +1940,7 @@ describe("`cancel` on non cancellable thenable created by then", function () {
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
done
();
},
20
);
},
20
);
...
...
@@ -1939,6 +1959,7 @@ describe("`cancel` on non cancellable thenable created by then", function () {
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
promise2
.
rejectedReason
.
message
,
"
Foo
"
);
done
();
},
20
);
},
20
);
...
...
@@ -2578,6 +2599,7 @@ describe("`RSVP.Queue`", function () {
it
(
'
should `cancel` pending success `thenable`
'
,
function
(
done
)
{
var
thenable_cancel_called
=
false
,
thenable_cancel_msg
,
thenable_ongoing
=
false
,
later_success_thenable_called
=
false
,
later_error_thenable_called
=
false
,
...
...
@@ -2587,8 +2609,9 @@ describe("`RSVP.Queue`", function () {
function
()
{
thenable_ongoing
=
true
;
},
function
()
{
function
(
msg
)
{
thenable_cancel_called
=
true
;
thenable_cancel_msg
=
msg
;
});
})
.
push
(
...
...
@@ -2610,6 +2633,7 @@ describe("`RSVP.Queue`", function () {
assert
.
equal
(
thenable_ongoing
,
true
);
queue
.
cancel
(
"
Foo
"
);
assert
.
equal
(
thenable_cancel_called
,
true
);
assert
.
equal
(
thenable_cancel_msg
,
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
true
);
...
...
@@ -2628,6 +2652,7 @@ describe("`RSVP.Queue`", function () {
it
(
'
should `cancel` pending error `thenable`
'
,
function
(
done
)
{
var
thenable_cancel_called
=
false
,
thenable_cancel_msg
,
thenable_ongoing
=
false
,
later_success_thenable_called
=
false
,
later_error_thenable_called
=
false
,
...
...
@@ -2640,8 +2665,9 @@ describe("`RSVP.Queue`", function () {
function
()
{
thenable_ongoing
=
true
;
},
function
()
{
function
(
msg
)
{
thenable_cancel_called
=
true
;
thenable_cancel_msg
=
msg
;
});
})
.
push
(
...
...
@@ -2663,6 +2689,7 @@ describe("`RSVP.Queue`", function () {
assert
.
equal
(
thenable_ongoing
,
true
);
queue
.
cancel
(
"
Foo
"
);
assert
.
equal
(
thenable_cancel_called
,
true
);
assert
.
equal
(
thenable_cancel_msg
,
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
true
);
...
...
@@ -2682,6 +2709,7 @@ describe("`RSVP.Queue`", function () {
it
(
'
should `cancel` propagate message to CancellationError
'
,
function
(
done
)
{
var
error
,
thenable_cancel_called
=
false
,
thenable_cancel_msg
,
thenable_ongoing
=
false
,
queue
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
@@ -2692,8 +2720,9 @@ describe("`RSVP.Queue`", function () {
function
()
{
thenable_ongoing
=
true
;
},
function
()
{
function
(
msg
)
{
thenable_cancel_called
=
true
;
thenable_cancel_msg
=
msg
;
});
});
queue
.
fail
(
function
(
e
)
{
...
...
@@ -2703,6 +2732,7 @@ describe("`RSVP.Queue`", function () {
assert
.
equal
(
thenable_ongoing
,
true
);
queue
.
cancel
(
"
Propagate this message
"
);
assert
.
equal
(
thenable_cancel_called
,
true
);
assert
.
equal
(
thenable_cancel_msg
,
"
Propagate this message
"
);
setTimeout
(
function
()
{
assert
(
queue
.
rejectedReason
instanceof
RSVP
.
CancellationError
,
queue
.
rejectedReason
);
assert
(
error
instanceof
RSVP
.
CancellationError
,
error
);
...
...
Romain Courteaud
@romain
mentioned in commit
renderjs@9a7a349a
·
Dec 14, 2021
mentioned in commit
renderjs@9a7a349a
mentioned in commit renderjs@9a7a349ac7daaae9768418e037271f4dd0253148
Toggle commit list
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