[Assorted-commits] SF.net SVN: assorted:[1905] sandbox/trunk/src/node
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2017-12-06 20:26:07
|
Revision: 1905
http://sourceforge.net/p/assorted/svn/1905
Author: yangzhang
Date: 2017-12-06 20:26:05 +0000 (Wed, 06 Dec 2017)
Log Message:
-----------
Add async demo
Added Paths:
-----------
sandbox/trunk/src/node/async/
sandbox/trunk/src/node/async/index.html
sandbox/trunk/src/node/async/index.js
sandbox/trunk/src/node/async/package.json
Added: sandbox/trunk/src/node/async/index.html
===================================================================
--- sandbox/trunk/src/node/async/index.html (rev 0)
+++ sandbox/trunk/src/node/async/index.html 2017-12-06 20:26:05 UTC (rev 1905)
@@ -0,0 +1,4 @@
+<script>
+const process = {argv: [null,null,5]};
+</script>
+<script src='index.js'></script>
Copied: sandbox/trunk/src/node/async/index.js (from rev 1904, sandbox/trunk/src/node/native-promises/index.js)
===================================================================
--- sandbox/trunk/src/node/async/index.js (rev 0)
+++ sandbox/trunk/src/node/async/index.js 2017-12-06 20:26:05 UTC (rev 1905)
@@ -0,0 +1,28 @@
+const mode = process.argv[2];
+console.log('mode', mode);
+function sleep() {
+ return new Promise(resolve => setTimeout(resolve, 1));
+}
+async function thrower() {
+ await sleep();
+ throw '!';
+}
+if (mode == 0) {
+} else if (mode == 1) {
+} else if (mode == 2) {
+} else if (mode == 3) {
+} else if (mode == 4) {
+ thrower();
+} else if (mode == 5) {
+ // Does not break!
+ (async function() {
+ await thrower();
+ })();
+} else if (mode == 6) {
+ async function wrap() {
+ //await new Promise(resolve => thrower().then(resolve));
+ await new Promise(resolve => thrower());
+ }
+ wrap();
+} else if (mode == 7) {
+}
Added: sandbox/trunk/src/node/async/package.json
===================================================================
--- sandbox/trunk/src/node/async/package.json (rev 0)
+++ sandbox/trunk/src/node/async/package.json 2017-12-06 20:26:05 UTC (rev 1905)
@@ -0,0 +1,6 @@
+{
+ "name": "async",
+ "version": "1.0.0",
+ "main": "index.js",
+ "license": "MIT"
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|