Last active
August 29, 2015 14:17
-
-
Save tyage/53e605cd80521884ae01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"use strict"; | |
var _this = this; | |
var timer = function (sec) { | |
return new Promise(function (done) { | |
setTimeout(function () { | |
done(sec); | |
console.log("done"); | |
}, sec); | |
}); | |
}; | |
(function callee$0$0() { | |
var a; | |
return regeneratorRuntime.async(function callee$0$0$(context$1$0) { | |
while (1) switch (context$1$0.prev = context$1$0.next) { | |
case 0: | |
console.log("wait for 1 sec..."); | |
context$1$0.next = 3; | |
return timer(1000); | |
case 3: | |
console.log("wait for 1.5 sec..."); | |
context$1$0.next = 6; | |
return Promise.all([timer(1500), timer(1200)]); | |
case 6: | |
a = context$1$0.sent; | |
console.log("a is", a); | |
case 8: | |
case "end": | |
return context$1$0.stop(); | |
} | |
}, null, _this); | |
})(); |
This file contains hidden or 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
let timer = (sec) => new Promise((done) => { | |
setTimeout(() => { | |
done(sec); | |
console.log('done'); | |
}, sec); | |
}); | |
(async () => { | |
console.log('wait for 1 sec...'); | |
await timer(1000); | |
console.log('wait for 1.5 sec...'); | |
let a = (await* [timer(1500), timer(1200)]); | |
console.log("a is", a) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment