Skip to content

Commit e251755

Browse files
authored
await emit in "receive" trigger (#27)
* Await emit in "receive" trigger
1 parent 0fe0073 commit e251755

File tree

4 files changed

+16
-33
lines changed

4 files changed

+16
-33
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.2.0 (February 13, 2020)
2+
3+
* "Receive" trigger awaits the result of emit
4+
* Update sailor version to 2.6.3
5+
* Remove "q" dependency
6+
17
## 1.1.2 (January 30, 2020)
28

39
* Update sailor version to 2.6.1

lib/triggers/receive.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
const Q = require('q');
2-
3-
// eslint-disable-next-line func-names
4-
exports.process = function (msg) {
1+
exports.process = async function receive(msg) {
52
const msgId = msg.id;
63
this.logger.info('Received new message:\n', JSON.stringify(msg));
74

@@ -28,27 +25,8 @@ exports.process = function (msg) {
2825
this.logger.info('Updated body: \n', JSON.stringify(msg.body));
2926
}
3027

31-
// eslint-disable-next-line consistent-this
32-
let self = this;
33-
34-
function emitData() {
35-
self.logger.info('Emitting data of message: ', msgId);
36-
self.emit('data', msg);
37-
}
38-
39-
function onError(e) {
40-
self.logger.info(e);
41-
self.emit('error', e);
42-
}
43-
44-
function onEnd() {
45-
self.logger.info('Finished processing message: ', msgId);
46-
self.emit('end');
47-
}
48-
49-
Q()
50-
.then(emitData)
51-
.fail(onError)
52-
.finally(onEnd);
28+
this.logger.info('Emitting data of message: ', msgId);
29+
await this.emit('data', msg);
30+
this.logger.info('Data emitted');
5331
};
5432

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webhook",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "elastic.io webhook component",
55
"scripts": {
66
"pretest": "eslint spec lib verifyCredentials.js --fix",
@@ -12,11 +12,10 @@
1212
"author": "elastic.io GmbH",
1313
"license": "Apache License 2.0",
1414
"dependencies": {
15-
"elasticio-sailor-nodejs": "2.6.1",
1615
"elasticio-node": "0.0.8",
16+
"elasticio-sailor-nodejs": "2.6.3",
1717
"node-uuid": "1.4.8",
18-
"request": "2.83.x",
19-
"q": "1.5.1"
18+
"request": "2.83.x"
2019
},
2120
"devDependencies": {
2221
"@elastic.io/component-logger": "0.0.1",

0 commit comments

Comments
 (0)