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
361f17d8
Commit
361f17d8
authored
Sep 26, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promise.then cancel on non cancellable thenable fixed
parent
a79070b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
1 deletion
+85
-1
lib/rsvp/promise.js
lib/rsvp/promise.js
+3
-1
test/tests/extension_test.js
test/tests/extension_test.js
+82
-0
No files found.
lib/rsvp/promise.js
View file @
361f17d8
...
@@ -201,7 +201,9 @@ function handleThenable(promise, value) {
...
@@ -201,7 +201,9 @@ function handleThenable(promise, value) {
if
(
isFunction
(
then
))
{
if
(
isFunction
(
then
))
{
promise
.
on
(
'
promise:cancelled
'
,
function
(
event
)
{
promise
.
on
(
'
promise:cancelled
'
,
function
(
event
)
{
value
.
cancel
();
if
(
isFunction
(
value
.
cancel
))
{
value
.
cancel
();
}
});
});
then
.
call
(
value
,
function
(
val
)
{
then
.
call
(
value
,
function
(
val
)
{
if
(
resolved
)
{
return
true
;
}
if
(
resolved
)
{
return
true
;
}
...
...
test/tests/extension_test.js
View file @
361f17d8
...
@@ -1591,6 +1591,88 @@ describe("`cancel` on promise created by then", function () {
...
@@ -1591,6 +1591,88 @@ 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
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
();}),
promise2
=
promise
.
then
(
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
()
{
cancel_called
=
true
;
}};
});
setTimeout
(
function
()
{
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
cancel_called
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
},
20
);
});
it
(
'
should cancel the pending rejected promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
reject
();}),
promise2
=
promise
.
then
(
undefined
,
function
()
{
return
{
"
then
"
:
function
()
{},
"
cancel
"
:
function
()
{
cancel_called
=
true
;
}};
});
setTimeout
(
function
()
{
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
cancel_called
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
},
20
);
});
});
describe
(
"
`cancel` on non cancellable thenable created by then
"
,
function
()
{
it
(
'
should cancel the pending fulfilled promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
();}),
promise2
=
promise
.
then
(
function
()
{
return
{
"
then
"
:
function
()
{}};
});
setTimeout
(
function
()
{
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
},
20
);
});
it
(
'
should cancel the pending rejected promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
reject
();}),
promise2
=
promise
.
then
(
undefined
,
function
()
{
return
{
"
then
"
:
function
()
{}};
});
setTimeout
(
function
()
{
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
},
20
);
});
});
describe
(
"
`always` on a promise
"
,
function
()
{
describe
(
"
`always` on a promise
"
,
function
()
{
it
(
'
should be a function
'
,
function
()
{
it
(
'
should be a function
'
,
function
()
{
var
promise
=
new
RSVP
.
Promise
(
function
(
done
,
fail
)
{});
var
promise
=
new
RSVP
.
Promise
(
function
(
done
,
fail
)
{});
...
...
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