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
558ac4dd
Commit
558ac4dd
authored
Sep 30, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cancel remaining promises if all/any is rejected.
parent
5b7ebbb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
lib/rsvp/all.js
lib/rsvp/all.js
+6
-1
test/tests/extension_test.js
test/tests/extension_test.js
+60
-0
No files found.
lib/rsvp/all.js
View file @
558ac4dd
...
...
@@ -48,11 +48,16 @@ function promiseAtLeast(expected_count, promises) {
}
}
function
cancelAll
(
rejectionValue
)
{
reject
(
rejectionValue
);
canceller
();
}
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
promise
=
promises
[
i
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
)
{
promise
.
then
(
resolver
(
i
),
reject
);
promise
.
then
(
resolver
(
i
),
cancelAll
);
}
else
{
resolveAll
(
i
,
promise
);
}
...
...
test/tests/extension_test.js
View file @
558ac4dd
...
...
@@ -723,6 +723,36 @@ describe("RSVP extensions", function() {
done
();
},
20
);
});
specify
(
'
cancel the array of promise as soon as rejected
'
,
function
(
done
)
{
var
firstResolver
,
secondResolver
;
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
firstResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
secondResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
setTimeout
(
function
()
{
firstResolver
.
reject
(
"
Foo
"
);
},
0
);
setTimeout
(
function
()
{
secondResolver
.
resolve
(
true
);
},
5000
);
var
all_promise
=
RSVP
.
all
([
first
,
second
]);
setTimeout
(
function
()
{
assert
(
first
.
isRejected
);
assert
.
equal
(
first
.
rejectedReason
,
"
Foo
"
);
assert
(
second
.
isRejected
);
assert
(
second
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
});
});
describe
(
"
RSVP.any
"
,
function
()
{
...
...
@@ -895,6 +925,36 @@ describe("RSVP extensions", function() {
done
();
},
20
);
});
specify
(
'
cancel the array of promise as soon as rejected
'
,
function
(
done
)
{
var
firstResolver
,
secondResolver
;
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
firstResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
secondResolver
=
{
resolve
:
resolve
,
reject
:
reject
};
});
setTimeout
(
function
()
{
firstResolver
.
reject
(
"
Foo
"
);
},
0
);
setTimeout
(
function
()
{
secondResolver
.
resolve
(
true
);
},
5000
);
var
all_promise
=
RSVP
.
any
([
first
,
second
]);
setTimeout
(
function
()
{
assert
(
first
.
isRejected
);
assert
.
equal
(
first
.
rejectedReason
,
"
Foo
"
);
assert
(
second
.
isRejected
);
assert
(
second
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
});
});
describe
(
"
RSVP.reject
"
,
function
(){
...
...
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