-
Notifications
You must be signed in to change notification settings - Fork 2
/
throwInFulfilled.html
46 lines (42 loc) · 1.02 KB
/
throwInFulfilled.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<script src="../lib/MetaObject/q/q.js"></script>
<script>
// Accept a promise for load, and report the success or failure of the load
function foo(loaded) {
return Q.when(
loaded,
function glory(loaded){
// Ooops the processing of success path fails!
throw new Error("You lose");
console.log("We have ", loaded);
},
function fail(err) {
console.error("We have "+err);
}
);
};
// Create a promise for a load
function promiseLoaded() {
var defer = Q.defer();
window.addEventListener(
'load',
function(event) {
defer.resolve("success");
},
false
);
return defer.promise;
}
function main() {
// foo returns a promise, but we don't look at the return so we lose.
foo(promiseLoaded());
}
main();
</script>
</head>
<body>
<h1>Bad developer ergonomics: throw in promise fulfillment swallows exception</h1>
<p>May be related to <a href="https://github.com/kriskowal/q/issues/23">Issue 23 on github q</a>
</body>
</html>