From 4918c6ce0bc8ad6a457fee9addae7e2b0b89117b Mon Sep 17 00:00:00 2001 From: KoalaMoala Date: Mon, 28 Dec 2020 18:11:37 +0100 Subject: [PATCH 1/2] refacto(writable-bulk): change custom event name as it collides with a native one --- README.md | 6 +++--- lib/writable-bulk.js | 2 +- test/test-write.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d2424ef..38517d2 100644 --- a/README.md +++ b/README.md @@ -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(); }); ``` diff --git a/lib/writable-bulk.js b/lib/writable-bulk.js index e58166c..55583f4 100644 --- a/lib/writable-bulk.js +++ b/lib/writable-bulk.js @@ -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)); } diff --git a/test/test-write.js b/test/test-write.js index 6c4bbf2..24c1094 100644 --- a/test/test-write.js +++ b/test/test-write.js @@ -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); }); From 3310401cbbe91433a074d9c5bb95819b96bc21b0 Mon Sep 17 00:00:00 2001 From: KoalaMoala Date: Tue, 13 Jul 2021 15:22:54 +0200 Subject: [PATCH 2/2] refacto(*): change custom event name --- README.md | 6 +++--- lib/writable-bulk.js | 2 +- test/test-write.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 38517d2..7b5f90d 100644 --- a/README.md +++ b/README.md @@ -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 `custom_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 custom_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('custom_close', function () { +ws.on('elasticsearch_streams_close', function () { client.close(); }); ``` diff --git a/lib/writable-bulk.js b/lib/writable-bulk.js index 55583f4..82ae0e8 100644 --- a/lib/writable-bulk.js +++ b/lib/writable-bulk.js @@ -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('custom_close'); + this.emit('elasticsearch_streams_close'); }.bind(this)); }.bind(this)); } diff --git a/test/test-write.js b/test/test-write.js index 24c1094..db7399d 100644 --- a/test/test-write.js +++ b/test/test-write.js @@ -21,7 +21,7 @@ describe('When writing', function() { ws = new WritableBulk(bulkExec); ws.on('error', function(e) { err = e; - }).on('custom_close', function() { + }).on('elasticsearch_streams_close', function() { done(err); });