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
| !function() { | |
| var a = 1, | |
| b = 2, | |
| c = 3; | |
| console.log(a + b); | |
| console.log(a*b*c); | |
| }(); |
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
| function delay(v, t) { | |
| var d = jQuery.Deferred(); | |
| setTimeout(function() { | |
| d.resolve(v); | |
| }, t); | |
| return d.promise(); | |
| } |
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
| !function() { | |
| var a = delay(1, 1000), | |
| b = delay(2, 2000), | |
| c = delay(3, 3000); | |
| console.log(a + b); | |
| console.log(a*b*c); | |
| }(); |
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
| function async(f) { | |
| var g = f(); // get generator | |
| function h(v, e) { | |
| var t = e ? g.throw(e) : g.send(v); | |
| if (t.done) | |
| return; | |
| if (t.value.then) { | |
| t.value.then(function(v) { |
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
| async(function*() { | |
| var a = yield delay(1, 1000), | |
| b = yield delay(2, 2000), | |
| c = yield delay(3, 3000); | |
| console.log(a + b); | |
| console.log(a*b*c); | |
| }); |
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
| async(function*() { | |
| var a = delay(1, 1000), | |
| b = delay(2, 2000), | |
| c = delay(3, 3000); | |
| a = yield a; | |
| b = yield b; | |
| console.log(a + b); | |
| c = yield c; |
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
| async(function*() { | |
| try { | |
| var a = delay(1, 1000), | |
| b = delay(2, 2000), | |
| c; | |
| try { | |
| c = delay(3, 3000); | |
| } catch(e) { | |
| // something happened with "c" calculation |
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
| try { | |
| async(function*() { | |
| var a = yield delay(1, 1000); | |
| throw new Error('some error'); | |
| }); | |
| } catch(e) { | |
| console.log(e); | |
| } |
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
| function async(f) { | |
| var d = jQuery.Deferred(); | |
| var g = f(); // get generator | |
| function h(v, e) { | |
| var t; | |
| try { | |
| t = e ? g.throw(e) : g.send(v); | |
| } catch(e) { |
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
| async(function*() { | |
| try { | |
| yield async(function*() { | |
| var a = yield delay(1, 1000); | |
| throw new Error('some error'); | |
| }); | |
| } catch(e) { | |
| console.log(e); | |
| } | |
| }); |
OlderNewer