Skip to content

Node 14 #24

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

Open
wants to merge 2 commits into
base: master
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
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 `elasticsearch_streams_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 elasticsearch_streams_close the ES client as soon as we are done:

```js
ws.on('close', function () {
ws.on('elasticsearch_streams_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('elasticsearch_streams_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('elasticsearch_streams_close', function() {
done(err);
});

Expand Down