Skip to content

Instantly share code, notes, and snippets.

@burnjohn
Created March 27, 2019 19:54
Show Gist options
  • Save burnjohn/2758ec98ab88cd145da1560ec318bd77 to your computer and use it in GitHub Desktop.
Save burnjohn/2758ec98ab88cd145da1560ec318bd77 to your computer and use it in GitHub Desktop.
const promisify = (func) => () => new Promise((resolve) => func(resolve));
const showBackground = (resolve) => {
setTimeout(() => {
console.log('showBackground works!!!');
resolve();
} , 3000);
};
const slideSidebar = (resolve) => {
setTimeout(() => {
console.log('slideSidebar works!!!');
resolve();
} , 3000);
};
const showMenu = (resolve) => {
setTimeout(() => {
console.log('showMenu works!!!');
resolve();
} , 3000);
};
const showCloseBtn = (resolve) => {
setTimeout(() => {
console.log('showCloseBtn works!!!');
resolve();
} , 3000);
};
const showBackgroundAsync = promisify(showBackground);
const slideSidebarAsync = promisify(slideSidebar);
const showMenuAsync = promisify(showMenu);
const showCloseBtnAsync = promisify(showCloseBtn);
// (async() => {
// await showBackgroundAsync();
// await slideSidebarAsync();
// await showMenuAsync();
// await showCloseBtnAsync();
//
// })();
// showBackgroundAsync()
// .then(slideSidebarAsync)
// .then(showMenuAsync)
// .then(showCloseBtnAsync);
(async() => {
const operations = [showBackgroundAsync, slideSidebarAsync, showMenuAsync, showCloseBtnAsync];
for (let i = 0; i < operations.length; i++) {
const operation = operations[i];
await operation();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment