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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
rsvp.js
Commits
bebc30b9
Commit
bebc30b9
authored
Sep 30, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent resolving a promise twice.
parent
d6449937
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
2 deletions
+52
-2
lib/rsvp/promise.js
lib/rsvp/promise.js
+7
-0
test/tests/extension_test.js
test/tests/extension_test.js
+45
-2
No files found.
lib/rsvp/promise.js
View file @
bebc30b9
...
...
@@ -78,6 +78,9 @@ var invokeCallback = function(type, promise, callback, event) {
var
hasCallback
=
isFunction
(
callback
),
value
,
error
,
succeeded
,
failed
;
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
if
(
hasCallback
)
{
try
{
value
=
callback
(
event
.
detail
);
...
...
@@ -207,6 +210,8 @@ function handleThenable(promise, value) {
function
fulfill
(
promise
,
value
)
{
config
.
async
(
function
()
{
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
promise
.
trigger
(
'
promise:resolved
'
,
{
detail
:
value
});
promise
.
isFulfilled
=
true
;
promise
.
fulfillmentValue
=
value
;
...
...
@@ -215,6 +220,8 @@ function fulfill(promise, value) {
function
reject
(
promise
,
value
)
{
config
.
async
(
function
()
{
if
(
promise
.
isFulfilled
)
{
return
;
}
if
(
promise
.
isRejected
)
{
return
;
}
promise
.
trigger
(
'
promise:failed
'
,
{
detail
:
value
});
promise
.
isRejected
=
true
;
promise
.
rejectedReason
=
value
;
...
...
test/tests/extension_test.js
View file @
bebc30b9
...
...
@@ -1489,6 +1489,50 @@ describe("`cancel` on promise created by then", function () {
assert
.
equal
(
typeof
promise
.
cancel
,
"
function
"
);
});
it
(
'
should stop parent fulFillment propagation
'
,
function
(
done
)
{
var
promise
=
new
RSVP
.
resolve
(
1
),
promise2
=
promise
.
then
();
promise2
.
cancel
(
"
Foo
"
);
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
});
it
(
'
should stop parent rejection propagation
'
,
function
(
done
)
{
var
reject_count
=
0
,
promise
=
new
RSVP
.
reject
(
1
),
promise2
=
promise
.
fail
(
function
()
{
reject_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
(
reject_count
,
1
);
done
();
},
20
);
});
it
(
'
should not be callable twice
'
,
function
(
done
)
{
var
reject_count
=
0
,
promise
=
new
RSVP
.
reject
(
1
),
promise2
=
promise
.
fail
(
function
()
{
reject_count
+=
1
;});
promise2
.
cancel
(
"
Foo
"
);
promise2
.
cancel
(
"
Bar
"
);
setTimeout
(
function
()
{
assert
.
equal
(
promise2
.
isRejected
,
true
);
assert
.
equal
(
promise2
.
isFulfilled
,
undefined
);
assert
(
promise2
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
reject_count
,
1
);
done
();
},
20
);
});
it
(
'
should cancel the pending fulfilled promise
'
,
function
(
done
)
{
var
cancel_called
=
false
,
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
();}),
...
...
@@ -1804,13 +1848,12 @@ describe("`RSVP.Queue`", function () {
assert
(
promise
instanceof
RSVP
.
Promise
);
});
it
(
'
should work without `new`
'
,
function
(
done
)
{
it
(
'
should work without `new`
'
,
function
()
{
var
promise
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
'
value
'
;
});
promise
.
then
(
function
(
value
)
{
assert
.
equal
(
value
,
'
value
'
);
done
();
});
});
});
...
...
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