Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const functions = [
- (callback) => {
- setTimeout (() => {
- console.log(4);
- callback && callback();
- }, 4000);
- },
- (callback) => {
- setTimeout (() => {
- console.log(2);
- callback && callback();
- }, 2000);
- }
- ]
- const wait = async (arr, cb) => {
- // currently 'all done' is displayed before 2, 4
- await new Promise((resolve, reject) => {
- for (let func of arr) {
- func();
- }
- resolve();
- });
- cb();
- }
- const callback = () => {
- console.log('all done');
- }
- wait(functions, callback);
Advertisement
Add Comment
Please, Sign In to add comment