-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3df7f0
commit d874d8c
Showing
11 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
setTimeout(()=>console.log("TIMED OUT!"), 300); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
function iterate (num) { | ||
console.log(num); | ||
return ++num; | ||
}; | ||
|
||
function alwaysThrows () { | ||
throw new Error("OH NOES"); | ||
}; | ||
|
||
Promise.resolve(iterate(1)) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(alwaysThrows) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(iterate) | ||
.then(null, console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
var promise = new Promise( (fulfill, reject)=> | ||
setTimeout( ()=>fulfill("FULFILLED!"), 300) | ||
); | ||
|
||
promise.then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
var promise = new Promise(function (fulfill, reject) { | ||
setTimeout(()=>reject(new Error("REJECTED!")),300); | ||
}); | ||
|
||
function onReject (error) { | ||
console.log(error.message); | ||
} | ||
|
||
promise.then(null, onReject); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
let promise = new Promise(function(fulfill, reject){ | ||
fulfill("I FIRED"); | ||
reject(new Error("I DID NOT FIRE")); | ||
}) | ||
|
||
promise.then(console.log, (error)=>console.log(error.message)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
let promise = new Promise(function(fulfill, reject){ | ||
fulfill('PROMISE VALUE'); | ||
}); | ||
|
||
promise.then(console.log, null); | ||
|
||
console.log('MAIN PROGRAM'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var message; | ||
var promise; | ||
|
||
function randomBytes(n) { | ||
return (Math.random() * Math.pow(256, n) | 0).toString(16); | ||
} | ||
|
||
message = | ||
'A fatal exception ' + randomBytes(1) + ' has occurred at ' + | ||
randomBytes(2) + ':' + randomBytes(4) + '. Your system\nwill be ' + | ||
'terminated in 3 seconds.'; | ||
|
||
promise = Promise.reject(new Error(message)); | ||
|
||
promise.catch(function (err) { | ||
var i = 3; | ||
|
||
process.stderr.write(err.message); | ||
|
||
setTimeout(function boom() { | ||
process.stderr.write('\rwill be terminated in ' + (--i) + ' seconds.'); | ||
if (!i) { | ||
process.stderr.write('\n..... . . . boom . . . .....\n'); | ||
} else { | ||
setTimeout(boom, 1000); | ||
} | ||
}, 1000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict' | ||
|
||
first().then(second) | ||
.then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
function attachTitle(name){ | ||
return 'DR. ' + name; | ||
} | ||
|
||
let promise = Promise.resolve("MANHATTAN"); | ||
|
||
promise.then(attachTitle).then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
|
||
function parsePromised(someJson){ | ||
return new Promise( (fulfill, reject)=>{ | ||
try { | ||
fulfill(JSON.parse(someJson)); | ||
} | ||
catch(error){ | ||
console.log(error); | ||
} | ||
} | ||
); | ||
}; | ||
|
||
parsePromised(process.argv[2]).then(null, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "promise-shop", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |