Skip to content

Commit 8879169

Browse files
authored
Merge pull request #1 from KoalaMoala/chore/node14
refacto(writable-bulk): change custom event name as it collides with a native one
2 parents 64c220e + 3310401 commit 8879169

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ var toBulk = new TransformToBulk(function getIndexTypeId(doc) { return { _id: do
3737
require('random-document-stream')(42).pipe(toBulk).pipe(ws).on('finish', done);
3838
```
3939

40-
NOTE: One must listen to the `close` event emitted by the write stream to know
40+
NOTE: One must listen to the `elasticsearch_streams_close` event emitted by the write stream to know
4141
when all the data has been written and flushed to Elasticsearch.
4242

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

46-
For example to close the ES client as soon as we are done:
46+
For example to elasticsearch_streams_close the ES client as soon as we are done:
4747

4848
```js
49-
ws.on('close', function () {
49+
ws.on('elasticsearch_streams_close', function () {
5050
client.close();
5151
});
5252
```

lib/writable-bulk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function WritableBulk(bulkExec, highWaterMark) {
2929
// Not great. See: https://github.com/joyent/node/issues/5315#issuecomment-16670354
3030
this.on('finish', function() {
3131
this._flushBulk(function() {
32-
this.emit('close');
32+
this.emit('elasticsearch_streams_close');
3333
}.bind(this));
3434
}.bind(this));
3535
}

test/test-write.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('When writing', function() {
2121
ws = new WritableBulk(bulkExec);
2222
ws.on('error', function(e) {
2323
err = e;
24-
}).on('close', function() {
24+
}).on('elasticsearch_streams_close', function() {
2525
done(err);
2626
});
2727

0 commit comments

Comments
 (0)