forked from beautifulcoder/FunWithCallbacks
-
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.
Add async/await to wrap around the Promise
- Loading branch information
1 parent
d741be7
commit 85fb597
Showing
2 changed files
with
40 additions
and
1 deletion.
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,38 @@ | ||
var pipeDelimiter = require('./pipeDelimiter'); | ||
|
||
async function run() { | ||
await buildFerociousCats({ list: '', delimiter: pipeDelimiter }, 'Panther', getJaguar) | ||
console.log('DONE'); | ||
} | ||
|
||
function getJaguar(cat) { | ||
return buildFerociousCats(cat, 'Jaguar', getLynx); | ||
} | ||
|
||
function getLynx(cat) { | ||
return buildFerociousCats(cat, 'Lynx', getSnowLeopard); | ||
} | ||
|
||
function getSnowLeopard(cat) { | ||
return buildFerociousCats(cat, 'Snow Leopard', getLion); | ||
} | ||
|
||
function getLion(cat) { | ||
return buildFerociousCats(cat, 'Lion', printList); | ||
} | ||
|
||
function printList(cat) { | ||
console.log(cat.list); | ||
} | ||
|
||
function buildFerociousCats(cat, returnValue, next) { | ||
return new Promise((resolve) => { | ||
setTimeout(function asyncCall(data) { | ||
var catList = cat.delimiter(cat.list, data); | ||
|
||
resolve(next({ list: catList, delimiter: cat.delimiter })); | ||
}, 1, returnValue); | ||
}); | ||
} | ||
|
||
run().then(() => console.log('DONE DONE')); |
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