forked from shama/letswritecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (32 loc) · 816 Bytes
/
Copy pathindex.js
File metadata and controls
36 lines (32 loc) · 816 Bytes
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
var fetch = require('./fetch.js')
// Using then and catch
// var promise = fetch('bears.txt')
//
// promise.then(function (bears) {
// console.log(bears)
// //throw new Error('Uh oh')
// return fetch('fish.txt')
// }).then(function (fish) {
// console.log(fish)
// }).catch(function (err) {
// console.error('WE GOT ERROR', err)
// })
// Using Promise.all
// Promise.all([
// fetch('bears.txt'),
// fetch('fish.txt'),
// ]).then(function (values) {
// var bears = values[0]
// var fish = values[1]
// console.log(bears, fish)
// })
// Creating promises
var promise = new Promise(function (resolve, reject) {
//reject(new Error("uh oh"))
resolve('all good')
})
promise.then(function (result) {
console.log('was it good?', result)
}).catch(function (err) {
console.error('ERR', err)
})