-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-promies.js
More file actions
45 lines (45 loc) · 1.2 KB
/
Copy pathexample-promies.js
File metadata and controls
45 lines (45 loc) · 1.2 KB
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
// function getTemCallback (location, callback) {
// callback(undefined, 78);
// callback("City not found");
// }
//
// getTemCallback("Oslo", function (err, temp) {
// if(err){
// console.log("error", err)
// }
// else{
// console.log("success", temp)
// }
// });
// function getTempPromise(location){
// return new Promise(function (resolve, reject) {
// setTimeout(function () {
// resolve(57);
// reject("City not found");
// }, 1000);
// });
// }
//
// getTempPromise("Oslo").then(function (temp) {
// console.log("promes success", temp);
// }, function (err) {
// console.log("promes error", err);
// });
function addPromise(a, b){
return new Promise(function (resolve, reject) {
setTimeout(function () {
if((typeof a === "number") && (typeof b === "number"))
{
resolve(a+b);
}
else
{
reject("a or b is not a number");
}}, 1000);
});
}
addPromise(2,"d").then(function (sum) {
console.log("promes success", sum);
}, function (err) {
console.log("promes error", err);
});