Skip to content

Commit 3f07ead

Browse files
committed
fix: add context to event listener aiife
1 parent 2898ff6 commit 3f07ead

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/backend/src/services/EventService.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19+
const { Context } = require("../util/context");
1920
const BaseService = require("./BaseService");
2021

2122
class ScopedEventBus {
@@ -55,7 +56,7 @@ class EventService extends BaseService {
5556

5657
// IIAFE wrapper to catch errors without blocking
5758
// event dispatch.
58-
(async () => {
59+
Context.arun(async () => {
5960
try {
6061
await callback(key, data, meta);
6162
} catch (e) {
@@ -65,14 +66,14 @@ class EventService extends BaseService {
6566
alarm: true,
6667
});
6768
}
68-
})();
69+
});
6970
}
7071
}
7172

7273
for ( const callback of this.global_listeners_ ) {
7374
// IIAFE wrapper to catch errors without blocking
7475
// event dispatch.
75-
(async () => {
76+
Context.arun(async () => {
7677
try {
7778
await callback(key, data, meta);
7879
} catch (e) {
@@ -82,7 +83,7 @@ class EventService extends BaseService {
8283
alarm: true,
8384
});
8485
}
85-
})();
86+
});
8687
}
8788

8889
}

src/backend/src/util/context.js

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class Context {
6060
static describe () {
6161
return this.get().describe();
6262
}
63+
static arun (cb) {
64+
return this.get().arun(cb);
65+
}
6366
get (k) {
6467
return this.values_[k];
6568
}

0 commit comments

Comments
 (0)