nv-cli-sync-and-async
v1.0.2
Published
nv-cli-sync-and-async ===================== - nv-cli-sync-and-async is a simple cli-tool - creat sync-version of source-code AND async-version of source code
Downloads
2
Readme
nv-cli-sync-and-async
- nv-cli-sync-and-async is a simple cli-tool
- creat sync-version of source-code AND async-version of source code
install
- npm install nv-cli-sync-and-async -g
usage
Usage: nv_sync_and_async [options]
Options:
-i, --input input string ,default stdin
-o, --output output string,default stdout
-h, --help usage
example
file to file
//this source code write as follows<see cat-of-lib.js below>:
// IF await scope-function-node is NOT async:
// will creat both a sync-version AND a async-version
// IF await scope-function-node is async:
// will do nothing
# cat lib.js
function maybe(G,other) {
let acc = 0;
for await(let each of G) {
acc = acc + each
}
acc = acc + (await other)
return(acc)
}
module.exports = maybe
#
# nv_sync_and_async -i lib.js -o mylib.js
# ls -l | egrep mylib
-rw-r--r-- 1 root root 185 Mar 4 03:06 mylib.async.js
-rw-r--r-- 1 root root 164 Mar 4 03:06 mylib.sync.js
# cat mylib.async.js
//ASYNC:
async function maybe(G, other) {
let acc = 0;
for await (let each of G) {
acc = acc + each;
}
acc = acc + (await other);
return acc;
}
module.exports = maybe;
#
# cat mylib.sync.js
//SYNC:
function maybe(G, other) {
let acc = 0;
for (let each of G) {
acc = acc + each;
}
acc = acc + other;
return acc;
}
module.exports = maybe;
stdin to stdout
class Cls {
static smethod () {
while(true) {
d[await 3] = 100;
}
}
method() {
await 100
}
}
^C nv-cli-sync-and-async# node cli.js
class Cls {
static smethod () {
while(true) {
d[await 3] = 100;
}
}
method() {
await 100
}
}
//=============>press ctrl+D
//SYNC:
class Cls {
static smethod() {
while (true) {
d[3] = 100;
}
}
method() {
100;
}
}
/*================*/
//ASYNC:
class Cls {
static async smethod() {
while (true) {
d[await 3] = 100;
}
}
async method() {
await 100;
}
}
/*================*/
LICENSE
- ISC