UpSync: Callback -> Async/Await
Note: This module is intended to be used with Node.js 7+ or other JavaScript engines/transpilers that have support for ES2017 async/await.
This project is more my personal tool for learning Node.js support for JavaScript ES2017 async/await.
I thought it would be a fun exercise to write my own utility that takes a traditional callback-style function, and returns it wrapped in an async function. This is similar to some of the callback-to-promise utilities that are in various libraries.
Basic usage:
const upsync = ; // The old, callback way of doing things { const msg = `kicking it old school, eh ?`; ;} // upsync that suckerconst asyncSchool = ; // Let's use it { const response = await ; console;} ;
Same deal, but with fat arrows:
const upsync = ; // The old, callback way of doing thingsconst oldSchool = { const msg = `kicking it old school, eh ?`; ;}; // upsync that suckerconst asyncSchool = ; // Let's use itconst runThisThang = async { const response = await ; console;} ;
Okay, here's a slightly more legitimate example
const upsync = ;const fs = ;const readFile = ; const readAndParseJsonFile = async { try const contents = await ; return JSON; catch err console; throw err; }; const main = async { try const pkg = await ; console; catch err console; } // async functions return a promise;