Node.jsでのパイプ使用(readline)

[Node.jsでの標準入力(コンソール)について](https://qiita.com/yosgspec/items/6a1e18890510f49fef12)の続編っぽいようなそうでもないような記事。

前述していた記事を書いていた時にパイプの動作について勘違いしていたことを見つけたので動作を試してみた次第。
結論としてはPromiseを挟むとパイプでは正常に動作ができないようだった。

なので、パイプする場合は素直にprocess.stdin.onを使うかasync/awaitをあきらめる必要があるという何とも残念な結論。

あとrl.questionはパイプ非対応だった気がしたけど、使えたんだね。

以下実験で使用したソースファイルもろもろ。

# 実験用ソース

[AsyncPromise](https://paiza.io/projects/7sYvAc5SZNDRsM6hiH-s6g)

```js
const readline=require("readline");
const rl= readline.createInterface({
	input:process.stdin,
	output:process.stdout,
	terminal:false
});

(async function(){
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
	console.log(await new Promise(res=>rl.once("line",s=>res(s))));
})();
```
[GeneratorPromise](https://paiza.io/projects/QKBD38cfzbp6YB9NLu7JfQ)

```js
const readline=require("readline");
const rl= readline.createInterface({
	input:process.stdin,
	output:process.stdout,
	terminal:false
});

const g=(function*(){
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
	console.log(yield (new Promise(res=>rl.once("line",s=>res(s)))).then(s=>g.next(s)));
})();
g.next();
```
[Generator](https://paiza.io/projects/G37cDX2flmBHaO7SM_K4xA)

```js:
const readline=require("readline");
const rl= readline.createInterface({
	input:process.stdin,
	output:process.stdout,
	terminal:false
});

const g=(function*(){
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
	console.log(yield rl.once("line",s=>g.next(s)));
})();
g.next();
```
[GeneratorQuestion](https://paiza.io/projects/qf9z2FBW1oQ7ALMUETcs7w)

```js
const readline=require("readline");
const rl= readline.createInterface({
	input:process.stdin,
	output:process.stdout,
	terminal:false
});

const g=(function*(){
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
	console.log(yield rl.question("",s=>g.next(s)));
})();
g.next();
```