Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

練習問題実装 #1743

Open
wants to merge 1 commit into
base: master-2020
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
'use strict';
const fs = require('fs');
const fileName = './test.txt';
for (let count = 0; count < 30; count++) {
fs.appendFile(fileName, 'おはようございます\n', 'utf8', () => {});
fs.appendFile(fileName, 'こんにちは\n', 'utf8', () => {});
fs.appendFile(fileName, 'こんばんは\n', 'utf8', () => {});

function appendFilePromise(fileName, str) {
return new Promise((resolve) => {
fs.appendFile(fileName, str, 'utf8', () => resolve());
});
}
async function main() {
for (let count = 0; count < 500; count++) {
await appendFilePromise(fileName, 'あ');
await appendFilePromise(fileName, 'い');
await appendFilePromise(fileName, 'う');
await appendFilePromise(fileName, 'え');
await appendFilePromise(fileName, 'お');
await appendFilePromise(fileName, '\n');
}
}

main();
16 changes: 16 additions & 0 deletions app2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const fs = require('fs');
const fileName = './test.txt';

function appendFilePromise(fileName, str){
return new Promise((resolve) =>{
fs.appendFile(fileName, str, 'utf8', () => resolve());
});
}
async function main() {
for (let count = 0; count < 30; count++) {
await appendFilePromise(fileName, 'おはようございます\n');
await appendFilePromise(fileName, 'こんにちは\n');
await appendFilePromise(fileName, 'こんばんは\n');
}
}
19 changes: 19 additions & 0 deletions app3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
const fs = require('fs');
const fileName = './test.txt';

function appendFilePromise(fileName, str) {
return new Promise((resolve) => {
fs.appendFile(fileName, str, 'utf8', () => resolve());
});
}

for (let count = 0; count < 30; count++) {
appendFilePromise(fileName, 'おはようございます\n')
.then(() => {
return appendFilePromise(fileName, 'こんにちは\n');
})
.then(() => {
return appendFilePromise(fileName, 'こんばんは\n');
});
}