Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ var toBulk = new TransformToBulk(function getIndexTypeId(doc) { return { _id: do
require('random-document-stream')(42).pipe(toBulk).pipe(ws).on('finish', done);
```

NOTE: One must listen to the `close` event emitted by the write stream to know
NOTE: One must listen to the `custom_close` event emitted by the write stream to know
when all the data has been written and flushed to Elasticsearch.

Listening to `finish` does not mean much really as we are in this situation:
https://github.com/joyent/node/issues/5315#issuecomment-16670354

For example to close the ES client as soon as we are done:
For example to custom_close the ES client as soon as we are done:

```js
ws.on('close', function () {
ws.on('custom_close', function () {
client.close();
});
```
Expand Down
2 changes: 1 addition & 1 deletion lib/writable-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function WritableBulk(bulkExec, highWaterMark) {
// Not great. See: https://github.com/joyent/node/issues/5315#issuecomment-16670354
this.on('finish', function() {
this._flushBulk(function() {
this.emit('close');
this.emit('custom_close');
}.bind(this));
}.bind(this));
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('When writing', function() {
ws = new WritableBulk(bulkExec);
ws.on('error', function(e) {
err = e;
}).on('close', function() {
}).on('custom_close', function() {
done(err);
});

Expand Down