Skip to content

Commit

Permalink
PR feedback - invoke ready event on nextTick
Browse files Browse the repository at this point in the history
  • Loading branch information
admataz authored and mcollina committed Jul 15, 2020
1 parent 5e2b07a commit 8b112cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function openFile (file, sonic) {
if (sonic.sync) {
const fd = fs.openSync(file, 'a')
fileOpened(null, fd)
process.nextTick(() => sonic.emit('ready'))
} else {
fs.open(file, 'a', fileOpened)
}
Expand Down
58 changes: 9 additions & 49 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ function buildTests (test, sync) {
t.pass('ready emitted')
}

if (sync) {
onReady()
} else {
stream.on('ready', onReady)
}
stream.on('ready', onReady)

t.ok(stream.write('hello world\n'))
t.ok(stream.write('something else\n'))
Expand Down Expand Up @@ -139,11 +135,7 @@ function buildTests (test, sync) {
t.pass('ready emitted')
}

if (sync) {
onReady()
} else {
stream.on('ready', onReady)
}
stream.on('ready', onReady)

t.ok(stream.write('hello world\n'))
t.ok(stream.write('something else\n'))
Expand Down Expand Up @@ -232,11 +224,7 @@ function buildTests (test, sync) {
t.pass('ready emitted')
}

if (sync) {
onReady()
} else {
stream.on('ready', onReady)
}
stream.on('ready', onReady)

t.ok(stream.write('hello world\n'))
t.ok(stream.write('something else\n'))
Expand Down Expand Up @@ -278,11 +266,7 @@ function buildTests (test, sync) {
t.pass('ready emitted')
}

if (sync) {
onReady()
} else {
stream.on('ready', onReady)
}
stream.on('ready', onReady)

t.ok(stream.write('hello world\n'))
t.ok(stream.write('something else\n'))
Expand Down Expand Up @@ -334,10 +318,6 @@ function buildTests (test, sync) {
}

stream.once('ready', onReady)

if (sync) {
onReady()
}
})
})

Expand Down Expand Up @@ -377,18 +357,10 @@ function buildTests (test, sync) {
fs.renameSync(dest, after)
stream.reopen()

if (sync) {
innerOnReady()
} else {
stream.once('ready', innerOnReady)
}
stream.once('ready', innerOnReady)
}

if (sync) {
onReady()
} else {
stream.once('ready', onReady)
}
stream.once('ready', onReady)
})

test('reopen if not open', (t) => {
Expand Down Expand Up @@ -428,11 +400,7 @@ function buildTests (test, sync) {
stream.end()
}

if (sync) {
onReady()
} else {
stream.once('ready', onReady)
}
stream.once('ready', onReady)
})

test('end after 2x reopen', (t) => {
Expand All @@ -457,11 +425,7 @@ function buildTests (test, sync) {
stream.end()
}

if (sync) {
onReady()
} else {
stream.once('ready', onReady)
}
stream.once('ready', onReady)
})

test('end if not ready', (t) => {
Expand Down Expand Up @@ -514,11 +478,7 @@ function buildTests (test, sync) {
})
}

if (sync) {
onReady()
} else {
stream.once('ready', onReady)
}
stream.once('ready', onReady)
})
})

Expand Down

0 comments on commit 8b112cb

Please sign in to comment.