Skip to content

Commit 7818c4c

Browse files
committed
Register finish listener in createWriteStream example earlier
1 parent 6fe0b5d commit 7818c4c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ Make a write stream to append chunks as blocks.
286286
``` js
287287
const ws = core.createWriteStream()
288288

289+
// Listen for stream finishing
290+
const done = new Promise(resolve => ws.on('finish', resolve))
291+
289292
for (const data of ['hello', 'world']) ws.write(data)
290293
ws.end()
291294

292-
// Wait for stream to finish
293-
await new Promise(resolve => ws.on('finish', resolve))
295+
await done
294296

295297
console.log(await core.get(core.length - 2)) // 'hello'
296298
console.log(await core.get(core.length - 1)) // 'world'

0 commit comments

Comments
 (0)