-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
33 lines (29 loc) · 743 Bytes
/
test.mjs
File metadata and controls
33 lines (29 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'fs'
const ws=fs.createWriteStream('test.txt',{highWaterMark:50})
let i=1
function write() {
let canWrite=true
while (i<=100 && canWrite ) {
canWrite=ws.write(`line ${i} \n`)
console.log('writing',i,'->' ,canWrite)
++i
}
if (i<=100) {
ws.once('drain',write)
}else{
ws.end()
}
}
//write()
const fin=fs.createWriteStream('finish.txt')
fin.write('hello\n')
fin.end('finish line \n')
fin.on('close',()=>console.log('closed fired'))
fin.on('finish',()=>console.log('finish fired'))
import EventEmitter from 'events'
const emitter=new EventEmitter()
emitter.emit('split')
emitter.on('split',()=>console.log('split recieved'))
/*
setInterval(()=>{
},100) */